Published on :
Statistics SASHELP

Survival Analysis with Curves and Risk Tables

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by configuring the ODS (Output Delivery System) environment for graphic output. It then executes the LIFETEST procedure on the 'sashelp.BMT' dataset to perform a survival analysis stratified by the 'Group' variable. The survival plot data is captured in a dataset named 'SurvivalPlotData'. Subsequently, the SGPLOT procedure is used three times to generate different versions of a survival plot, varying the position and style of the subjects at risk table (outside or inside the plot) and the general ODS style.
Data Analysis

Type : SASHELP


The script exclusively uses the BMT dataset from the standard SASHELP library, which contains bone marrow transplant data.

1 Code Block
PROC LIFETEST Data
Explanation :
This block initializes the graphical output environment and executes the LIFETEST procedure. Survival analysis is performed on sashelp.BMT data, using the T variable for time and Status for the event. The analysis is stratified by 'Group'. Graphical results, including survival curve points, are saved in the 'SurvivalPlotData' table using the 'ods output' statement.
Copied!
1%let gpath='.';
2%let dpi=300;
3ods html close;
4ods listing style=htmlblue image_dpi=&dpi gpath=&gpath;
5 
6ods graphics on;
7ods OUTPUT Survivalplot=SurvivalPlotData;
8PROC LIFETEST DATA=sashelp.BMT plots=survival(atrisk=0 to 2500 BY 500);
9 time T * STATUS(0);
10 strata Group / test=logrank adjust=sidak;
11RUN;
2 Code Block
PROC SGPLOT
Explanation :
This block uses PROC SGPLOT to generate a survival curve (STEP statement) with markers for censored data (SCATTER statement). The main feature of this plot is the addition of a subjects at risk table (xaxistable) positioned outside, below the X-axis.
Copied!
1ods graphics / reset width=5in height=3in imagename='4_5_1_Survival Plot_SG_V94';
2title 'Product-Limit Survival Estimates';
3title2 h=0.8 'With Number of AML Subjects at Risk';
4PROC SGPLOT DATA=SurvivalPlotData;
5 step x=time y=survival / group=stratum lineattrs=(pattern=solid) name='s';
6 scatter x=time y=censored / markerattrs=(symbol=plus) name='c';
7 scatter x=time y=censored / markerattrs=(symbol=plus) GROUP=stratum;
8 xaxistable atrisk / x=tatrisk location=outside class=stratum colorgroup=stratum;
9 keylegend 'c' / location=inside position=topright;
10 keylegend 's';
11RUN;
3 Code Block
PROC SGPLOT
Explanation :
Similar to the previous block, this code generates the same survival curve. The key difference is that the subjects at risk table (xaxistable) is configured with 'location=inside', which places it at the bottom of the plot, superimposed on the plotting area.
Copied!
1ods listing style=htmlBlue;
2ods graphics / reset width=5in height=3in imagename='4_5_2_Survival Plot_Inner_SG_V94';
3title 'Product-Limit Survival Estimates';
4title2 h=0.8 'With Number of AML Subjects at Risk';
5PROC SGPLOT DATA=SurvivalPlotData;
6 step x=time y=survival / group=stratum lineattrs=(pattern=solid) name='s';
7 scatter x=time y=censored / markerattrs=(symbol=plus) name='c';
8 scatter x=time y=censored / markerattrs=(symbol=plus) GROUP=stratum;
9 xaxistable atrisk / x=tatrisk location=inside class=stratum colorgroup=stratum
10 separator valueattrs=(size=7 weight=bold) labelattrs=(size=8);
11 keylegend 'c' / location=inside position=topright;
12 keylegend 's';
13RUN;
4 Code Block
PROC SGPLOT
Explanation :
This last block changes the ODS style to 'journal' and generates a third version of the plot. The subjects at risk table is still inside. Aesthetic options are added, such as labels directly on the curves (curvelabel) and a different marker style for censored data (filled circle).
Copied!
1ods listing style=journal;
2ods graphics / reset width=5in height=3in imagename='4_5_3_Survival Plot_Inner_Journal_SG_V94';
3title 'Product-Limit Survival Estimates';
4title2 h=0.8 'With Number of AML Subjects at Risk';
5PROC SGPLOT DATA=SurvivalPlotData;
6 step x=time y=survival / group=stratum lineattrs=(pattern=solid) name='s'
7 curvelabel curvelabelattrs=(size=6) splitchar='-';
8 scatter x=time y=censored / name='c' markerattrs=(symbol=circlefilled size=4);
9 xaxistable atrisk / x=tatrisk location=inside class=stratum colorgroup=stratum
10 separator valueattrs=(size=7 weight=bold) labelattrs=(size=8);
11 keylegend 'c' / location=inside position=topright;
12RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.