Published on :
Statistics CREATION_INTERNE

Getting Started Example for PROC LIFETEST

This code is also available in: Deutsch Español Français
Awaiting validation
This script creates an internal dataset ('exposed') containing survival times, censoring statuses, and covariates (Treatment, Sex). It then performs several survival analyses: estimation of survival functions (Kaplan-Meier), tests of equality between groups (Log-Rank), and stratifications, all while using ODS Graphics to visualize the survival curves.
Data Analysis

Type : CREATION_INTERNE


Data is created directly within the script via a DATA step with the DATALINES statement.

1 Code Block
PROC FORMAT
Explanation :
Definition of a user-defined format to display 'Drug X' and 'Placebo' labels instead of numerical codes.
Copied!
1 
2PROC FORMAT;
3value Rx 1='Drug X' 0='Placebo';
4RUN;
5 
2 Code Block
DATA STEP Data
Explanation :
Creation of the 'exposed' dataset containing the variables Days, Status, Treatment, and Sex. Usage of the @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json instruction to read multiple observations per data line.
Copied!
1DATA exposed;
2 INPUT Days STATUS Treatment Sex $ @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3 FORMAT Treatment Rx.;
4 DATALINES;
5179 1 1 F 378 0 1 M
6256 1 1 F 355 1 1 M
7262 1 1 M 319 1 1 M
8256 1 1 F 256 1 1 M
9255 1 1 M 171 1 1 F
10224 0 1 F 325 1 1 M
11225 1 1 F 325 1 1 M
12287 1 1 M 217 1 1 F
13319 1 1 M 255 1 1 F
14264 1 1 M 256 1 1 F
15237 0 0 F 291 1 0 M
16156 1 0 F 323 1 0 M
17270 1 0 M 253 1 0 M
18257 1 0 M 206 1 0 F
19242 1 0 M 206 1 0 F
20157 1 0 F 237 1 0 M
21249 1 0 M 211 1 0 F
22180 1 0 F 229 1 0 F
23226 1 0 F 234 1 0 F
24268 0 0 M 209 1 0 F
25;
3 Code Block
PROC LIFETEST
Explanation :
Execution of survival analysis stratified by Treatment. Activation of ODS Graphics to produce survival curves with a table of subjects at risk and a log-survival curve.
Copied!
1ods graphics on;
2PROC LIFETEST DATA=Exposed plots=(survival(atrisk) logsurv);
3 time Days*STATUS(0);
4 strata Treatment;
5RUN;
6ods graphics off;
4 Code Block
PROC LIFETEST
Explanation :
Analysis stratified by Sex, comparing Treatment groups within each stratum. The 'notable' option suppresses the display of detailed survival tables.
Copied!
1PROC LIFETEST DATA=Exposed notable;
2 time Days*STATUS(0);
3 strata Sex / group=Treatment;
4RUN;
5 Code Block
PROC LIFETEST
Explanation :
Global test of the Treatment effect on survival (Log-Rank and Wilcoxon tests by default for two groups).
Copied!
1PROC LIFETEST DATA=Exposed notable;
2 time Days*STATUS(0);
3 test Treatment;
4RUN;
6 Code Block
PROC LIFETEST
Explanation :
Test of the Treatment effect adjusted for Sex (by stratifying by Sex). The 'test=none' option in strata prevents the homogeneity test between strata (Sex).
Copied!
1PROC LIFETEST DATA=Exposed notable;
2 time Days*STATUS(0);
3 strata Sex / test=none;
4 test Treatment;
5RUN;
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.
Copyright Info : SAS SAMPLE LIBRARY


Banner
Expert Advice
Expert
Stéphanie
Spécialiste Machine Learning et IA.
« Survival analysis is unique because it must account for censoring—the "Status" variable that indicates if an event actually occurred or if the subject simply left the study before the event happened. PROC LIFETEST is the primary tool for non-parametric estimation, specifically using the Kaplan-Meier method. »