Published on :
Statistical INTERNAL_CREATION

Bayesian Survival Analysis with PROC LIFEREG (Example 2)

This code is also available in: Deutsch Español Français
Awaiting validation
This script illustrates a survival analysis on industrial fan reliability data. It begins by creating the 'Fan' dataset containing operating times and censoring indicators. The LIFEREG procedure is then used to fit a log-normal parametric model with a Bayesian approach (BAYES statement), generating posterior samples in the 'Post' table. A subsequent DATA step uses these samples to estimate the probability distribution of failure at 8000 hours. Finally, PROC MEANS provides descriptive statistics (mean and percentiles) on this estimated probability.
Data Analysis

Type : INTERNAL_CREATION


Data is defined directly in the script via the 'datalines' statement in the DATA Fan step.

1 Code Block
DATA STEP Data
Explanation :
Creates the SAS table 'Fan' by reading internal data (datalines). The 'Lifetime' variable represents the lifespan and 'Censor' indicates whether the observation is censored (1) or not (0).
Copied!
1DATA Fan;
2 INPUT Lifetime Censor @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3 DATALINES;
4 450 0 460 1 1150 0 1150 0 1560 1
51600 0 1660 1 1850 1 1850 1 1850 1
61850 1 2030 1 2030 1 2030 1
72070 0 2070 0 2080 0 2200 1 3000 1
83000 1 3000 1 3000 1 3100 0 3200 1
93450 0 3750 1 3750 1 4150 1 4150 1
104150 1 4150 1 4300 1 4300 1 4300 1
114300 1 4600 0 4850 1 4850 1 4850 1
124850 1 5000 1 5000 1 5000 1 6100 1
136100 0 6100 1 6100 1 6300 1 6450 1
146450 1 6700 1 7450 1 7800 1 7800 1
158100 1 8100 1 8200 1 8500 1 8500 1
168500 1 8750 1 8750 0 8750 1 9400 1
179900 1 10100 1 10100 1 10100 1 11500 1
18;
2 Code Block
PROC LIFEREG
Explanation :
Performs a regression analysis on survival data with a log-normal distribution. The 'bayes' statement activates Bayesian analysis, sets a random seed for reproducibility (seed=1), and exports posterior distribution samples to the 'Post' table.
Copied!
1ods graphics on;
2PROC LIFEREG DATA=Fan;
3 model Lifetime*Censor( 1 )= / dist=lognormal;
4 bayes seed=1 outpost=Post;
5RUN;
3 Code Block
DATA STEP Data
Explanation :
Uses the estimated parameters (Intercept, Scale) stored in the 'Post' table to calculate the 'Frac' variable. This variable represents the estimated probability of failure at 8000 hours for each iteration of the Bayesian simulation.
Copied!
1DATA Prob;
2 SET Post;
3 Frac = ProbNorm(( log(8000) - Intercept ) / Scale );
4 label Frac= 'Fraction Failing in 8000 Hours';
5RUN;
4 Code Block
PROC MEANS
Explanation :
Calculates descriptive statistics (number of observations, mean, and various percentiles) on the 'Frac' variable from the 'Prob' table to summarize the posterior distribution of the probability of failure.
Copied!
1 
2PROC MEANS
3DATA = Prob(keep=Frac) n mean p10 p25 p50 p75 p90;
4RUN;
5 
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.