Published on :
Statistical INTERNAL_CREATION

Starter Example 1 for PROC LIFEREG

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a dataset named 'Headache' directly within the script using the `datalines` statement. This dataset contains variables for duration in minutes, treatment group, and a censoring indicator. After data creation, the script displays the first five observations of the 'Headache' dataset using PROC PRINT for a quick check. The main procedure is PROC LIFEREG, which is used to model survival data. It specifies 'Minutes' as the survival time variable, 'Censor' as the censoring status variable (where 1 indicates a censored event), and 'Group' as the explanatory classification variable. This procedure generates a new dataset 'New' which includes the cumulative distribution function (CDF) under the variable 'Prob'. Finally, PROC SGPLOT is employed to visualize the analysis results by generating a scatter plot. This plot represents 'Minutes' on the X-axis and 'Prob' (CDF) on the Y-axis, with data points grouped and colored according to the 'Group' variable, and a discrete legend is added for easier interpretation.
Data Analysis

Type : INTERNAL_CREATION


The 'Headache' dataset is created directly within the script using the `datalines` statement, providing data for survival analysis. The 'New' dataset is an intermediate result from PROC LIFEREG.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a SAS dataset named 'Headache'. The variables 'Minutes', 'Group', and 'Censor' are defined. Data is read in-line via the `datalines` statement, simulating results from a clinical trial or study with observation times and censoring indicators.
Copied!
1DATA Headache;
2 INPUT Minutes Group Censor;
3 DATALINES;
411 1 0 12 1 0 19 1 0 19 1 0
519 1 0 19 1 0 21 1 0 20 1 0
621 1 0 21 1 0 20 1 0 21 1 0
720 1 0 21 1 0 25 1 0 27 1 0
830 1 0 21 1 1 24 1 1 14 2 0
916 2 0 16 2 0 21 2 0 21 2 0
1023 2 0 23 2 0 23 2 0 23 2 0
1125 2 1 23 2 0 24 2 0 24 2 0
1226 2 1 32 2 1 30 2 1 30 2 0
1332 2 1 20 2 1
14;
2 Code Block
PROC PRINT
Explanation :
This block uses PROC PRINT to display the first five observations (rows) of the 'Headache' dataset. This is a common step to quickly verify the structure and content of the data after its creation or modification.
Copied!
1PROC PRINT DATA=headache (obs=5);
2RUN;
3 Code Block
PROC LIFEREG Data
Explanation :
This block executes PROC LIFEREG to perform an accelerated survival regression analysis on the 'Headache' dataset. The 'Group' variable is specified as a classification variable. The `model` statement defines the regression model, where 'Minutes' is the survival time variable, 'Censor' is the censoring status variable (with 1 indicating censoring, i.e., an unobserved event), and 'Group' is the explanatory variable. The `output` statement creates a new dataset 'New' that contains the original observations along with a new variable 'Prob' representing the estimated cumulative distribution function (CDF).
Copied!
1PROC LIFEREG DATA=Headache;
2 class Group;
3 model Minutes*Censor(1)=Group;
4 OUTPUT out=New cdf=Prob;
5RUN;
4 Code Block
PROC SGPLOT
Explanation :
This block uses PROC SGPLOT to generate a graphical visualization. It creates a scatter plot from the 'New' dataset created by PROC LIFEREG. 'Minutes' are represented on the X-axis and 'Prob' (CDF) values on the Y-axis. The `/ group=Group` option colors the data points according to the categories of the 'Group' variable, and `discretelegend` adds a discrete legend to identify these groups.
Copied!
1PROC SGPLOT DATA=New;
2 scatter x=Minutes y=Prob / group=Group;
3 discretelegend;
4RUN;
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