Published on :
Statistical CREATION_INTERNE

Survival Analysis with the LIFETEST Procedure

This code is also available in: Deutsch Español Français
Awaiting validation
The script is divided into four main analyses. The first two use the life-table method (METHOD=LIFE) on angina and lung cancer data, where data is grouped into time intervals. The third analysis uses the Kaplan-Meier estimator (METHOD=KM) on cancer data, generating an output survival table. The last analysis focuses on Hodgkin's disease and uses a stratified analysis (STRATA) to compare the survival functions of two distinct patient groups and visualize them on the same graph.
Data Analysis

Type : CREATION_INTERNE


All data required for the analysis (angina, lungcancer, cancer, hodgkin) are created directly within the script using DATA STEP instructions and in-line data (CARDS). No external data source is required.

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'angina' table from internal data. Variables are 'time', 'censor' (censoring indicator), and 'rep' (frequency). The '@@' operator allows reading multiple observations from the same data line.
Copied!
1DATA angina;
2 INPUT time censor rep @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3CARDS;
40.5 1 456 0.5 0 0 1.5 1 226 1.5 0 39
52.5 1 152 2.5 0 22 3.5 1 171 3.5 0 23
64.5 1 135 4.5 0 24 5.5 1 125 5.5 0 107
76.5 1 83 6.5 0 133 7.5 1 74 7.5 0 102
88.5 1 51 8.5 0 68 9.5 1 42 9.5 0 64
910.5 1 43 10.5 0 45 11.5 1 34 11.5 0 53
1012.5 1 18 12.5 0 33 13.5 1 9 13.5 0 27
1114.5 1 6 14.5 0 23 15.5 1 0 15.5 0 30
12;
13RUN;
2 Code Block
PROC LIFETEST
Explanation :
Performs a survival analysis on the 'angina' table using the life-table method (METHOD=LIFE) with specified intervals. It generates plots for the survival function (S) and the hazard function (H). The TIME statement defines the time variable and the censoring indicator (value 0). The FREQ statement specifies the frequency variable.
Copied!
1PROC LIFETEST DATA=angina METHOD=LIFE
2 INTERVALS= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
3 PLOTS=(S, H)
4 GRAPHICS;
5 TIME time*censor(0);
6 FREQ rep;
7RUN;
3 Code Block
DATA STEP Data
Explanation :
Creates the 'lungcancer' table in the same way as the 'angina' table, containing survival data for lung cancer.
Copied!
1DATA lungcancer;
2 INPUT time censor rep @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3CARDS;
40.5 1 82 0.5 0 0 1.5 1 30 1.5 0 8
52.5 1 27 2.5 0 8 3.5 1 22 3.5 0 7
64.5 1 26 4.5 0 7 5.5 1 25 5.5 0 28
76.5 1 20 6.5 0 31 7.5 1 11 7.5 0 32
88.5 1 14 8.5 0 24 9.5 1 13 9.5 0 27
910.5 1 5 10.5 0 22 11.5 1 5 11.5 0 23
1012.5 1 5 12.5 0 18 13.5 1 2 13.5 0 9
1114.5 1 3 14.5 0 7 15.5 1 3 15.5 0 11
12;
13RUN;
4 Code Block
PROC LIFETEST
Explanation :
Performs the same survival analysis as before, but on the 'lungcancer' table.
Copied!
1PROC LIFETEST DATA=lungcancer METHOD=LIFE
2 INTERVALS= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
3 PLOTS=(S, H)
4 GRAPHICS;
5 TIME time*censor(0);
6 FREQ rep;
7RUN;
5 Code Block
DATA STEP Data
Explanation :
Creates the 'cancer' table with individual survival times and a censoring indicator, preparing the data for a Kaplan-Meier type analysis.
Copied!
1DATA cancer;
2INPUT time censor @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3CARDS;
4 2.0 1 4.0 1 5.0 1 10.0 1
5 10.0 0 12 1 12 0 14 1
6 14 1 15 1 16 0 18 1
719 0 23 1 25 1 26 0
827 1 30 0 31 1 34 1
935 1 37 0 38 1 39 1
1042 0 43 0 46 1 47 0
1149 1 50 1 53 0 54 0
12;
13RUN;
6 Code Block
PROC LIFETEST
Explanation :
Performs a survival analysis with the Kaplan-Meier estimator (METHOD=KM). It generates a survival curve plot and saves the survival estimates into a new table named 'a' using the 'outsurv=a' option.
Copied!
1 
2PROC LIFETEST
3DATA=cancer METHOD=KM PLOTS=survival graphics outsurv = a;
4TIME time*censor(0);
5 
6RUN;
7 
7 Code Block
PROC PRINT
Explanation :
Displays the content of table 'a', which contains the detailed results of the survival function estimation calculated by the previous PROC LIFETEST step.
Copied!
1PROC PRINT DATA = a;
2RUN;
8 Code Block
DATA STEP Data
Explanation :
Creates the 'hodgkin' table containing data on Hodgkin's disease. It includes the 'group' variable which allows distinguishing two different patient cohorts.
Copied!
1DATA hodgkin;
2INPUT time censor group @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json ;
3CARDS;
41 1 1 2 1 1 5 1 1 5 1 1 5 1 1
57 1 1 9 1 1 11 1 1 11 1 1 13 1 1
613 1 1 16 1 1 20 1 1 21 1 1 22 0 1
722 1 1 31 0 1 33 0 1 37 0 1 43 1 1
81 1 2 3 1 2 4 1 2 4 1 2 5 1 2 7 1 2
97 1 2 9 1 2 9 1 2 14 0 2 17 1 2 19 0 2
1027 0 2 30 0 2 41 0 2
11;
12RUN;
9 Code Block
PROC LIFETEST
Explanation :
Performs a stratified survival analysis on the 'hodgkin' table. The 'STRATA group' statement instructs the procedure to calculate and test distinct survival functions for each value of the 'group' variable, allowing comparison of the two patient groups. The SYMBOL statements customize the appearance of lines on the survival plot.
Copied!
1PROC LIFETEST DATA=hodgkin PLOTS=(S) ;
2 TIME time*censor(0);
3 STRATA group;
4 SYMBOL1 V=NONE COLOR=BLACK LINE=1;
5 SYMBOL2 V=NONE COLOR=BLACK LINE=2;
6RUN;
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.