Hello,
I am currently try to simulate some log-normal and log-logistic distributed survival times in SAS. I have done it for Weibull and Exponential and have attempted to get a log normal however comes up with errors. If anyone could offer me any insight I would greatly appreciate it.
Regards,
Joey.
How have you done it for Weibull and Exponential? And how have you done it with log normal?
Show us your code and your log?
/* Weibull and Exponential */
%Let Lambda = 1000 ;
%Let Shape = 1 ; /* value of 1 for exponential */
%Let Time_Censor = 99999999999999;
%Let Beta0 = 1;
%Let Beta1 = 1.2;
%Let Sn=10;
Data Sim1A
( Drop = Linear_Predict Time_Censor Beta1 Lambda Shape Beta0);
Lambda = &Lambda. ;
Shape = &Shape.;
n= 10;
Time_Censor = &Time_Censor.;
Do Sim = 1 To &Sn. ;
Do n = 1 To n ;
ID + 1 ;
x1=rand('BERN',.5);
Beta0=&Beta0.;
Beta1=&Beta1.;
Linear_Predict = Exp(-(beta0* + (Beta1 * x1))) ;
Time = Rand( "WEIBULL", Shape ,Lambda* Linear_Predict) ;
If Time_Censor < Time
Then
Do ;
Censored = 1 ;
Time = Time_Censor ;
End ;
Else Censored = 0 ;
Output ;
End ;
End ;
Run ;
And the code for your attempt at lognormal or log-log?
If you get errors copy the code and error messages from the log and paste into a code box opened with the forums {i} icon to preserve formatting of any error diagnostics that appear. It is a good idea to paste code in either the code box or the box opened with the "running man" to preserve formatting as the message windows will remove a lot of white space.
I have fixed it now thank you, see below, I think I have done it correctly.
data Sim3
( Drop = Linear_Predict Beta1 Lambda Shape Beta0 Beta1);
Time_Censor = 999999999999999999;
Lambda = 1 ;
Shape = 2;
Do Sim = 1 To 1;
Do n = 1 To 10000 ;
ID + 1 ;
x1=rand('BERN',.5);
r=RAND("uniform");
Beta0 = 1;
Beta1 = 2;
Linear_Predict = Exp(-(beta0* + (Beta1 * x1))) ;
Time=(((1/r)-1)**(1/Shape))*(Linear_Predict);
If Time_Censor < Time
Then
Do ;
Censored = 1 ;
Time = Time_Censor ;
End ;
Else Censored = 0 ;
output;
End ;
End ;
run;
Why do you write
-(beta0* + (Beta1 * x1)) ?
This is equivalent to
-(beta0 * Beta1 * x1)
i.e., a model with intercept 0, unlike the more plausible
-(beta0 + Beta1 * x1)
Also, it would seem more familiar to me to omit the minus sign, so that the estimates of beta0 and beta1 are the "Intercept" and "x1" parameters in the output of a generic analysis like
proc lifereg data=sim3;
model time*censored(1)=x1 / dist=llogistic;
run;
But, of course, this is only a matter of parameterization.
When I perform simulations I always specify an initial seed value using the CALL STREAMINIT routine in order to get reproducible results.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.