A frequently asked question about the Survival Plot is: "How can I display the 'At Risk' data outside the plot area?". The survival plot rendered by the LIFETEST procedure displays the at risk data inside the plot data area. The reason for this is the potential for varying number of treatment groups. Here is a program from the procedure samples. The full program is shown here: SurvivalPlot
ods graphics / width=5in height=3.5in; proc lifetest data=BMT plots=survival(atrisk=0 to 2500 by 500); time T * Status(0); strata Group / test=logrank adjust=sidak; run;
As you can see in the graph above, the "At Risk" table is displayed inside the plot data are. This graph is created by the ProductLimitSurvival template for the LIFETEST procedure. This template uses a LAYOUT OVERLAY to plot the curves, and displays the at risk table in the Inner Margin at the bottom of the overlay container.
For a specific use case where you know the numbe of treatment groups, you can create a GTL program to display the data outside the plot area using data saved from the LIFETEST procedure as shown below.
Step 1: Run the LIFETEST procedure and save the survival plot data to a data set using the ODS OUTPUT statement:
ods output Survivalplot=SurvivalPlotData; proc lifetest data=BMT plots=survival(atrisk=0 to 2500 by 500); time T * Status(0); strata Group / test=logrank adjust=sidak; run;
Step 2: Now we define a GTL template called survival that uses a LAYOUT LATTICE with two rows and one column. Row weights of 85% for upper cell and 15% for lower cell are specified. For a different number of treatment groups you may want to adjust these values. ColumnDataRange=union is specified to ensure the x-axes of the two cells are uniform. This (incomplete) code snippet is shown below.
proc template; define statgraph survival; begingraph; entrytitle 'Product-Limit Survival Estimates'; entrytitle 'With Number of Subjects at Risk' / textattrs=graphfootnote; layout lattice / rows=2 rowweights=(0.85 0.15) columndatarange=union rowgutter=10; endlayout; endgraph; end; run;
Now, we add two cells inside the LAYOUT LATTICE, each defined by a LAYOUT OVERLAY block. The upper cell has the graphical plots of the data, and the lower cell has the "At Risk" data shown as a table using the BLOCKPLOT statement.
layout overlay; stepplot x=time y=survival / group=stratum name='a'; scatterplot x=time y=censored / name='b' markerattrs=(symbol=plus); scatterplot x=time y=censored / group=stratum markerattrs=(symbol=plus); discretelegend 'a'; discretelegend 'b' / location=inside halign=right valign=top border=true; endlayout; layout overlay / walldisplay=none xaxisopts=(display=none); blockplot x=tatrisk block=atrisk / display=(label values) class=stratumnum valuehalign=start; endlayout;
The resulting graph is shown below. The full code is shown here: SurvivalPlot_OutsideTable
Any update of the ProductLimitSurvival template for the LIFETEST procedure should be done with great care. This is a complex template that supports many different use cases.