SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Buchholz91
Calcite | Level 5

Buchholz91_0-1591810417218.png

 

Using the sample code above, how do I simulate survival data using certain specifications such as:

Buchholz91_1-1591810503864.png

 

My SAS skills are very rusty as I have not used it in over a year now. Any help would be greatly appreciated.

5 REPLIES 5
Reeza
Super User

Please do not post images of your code or question. It makes it harder to comment and modify it, unless I type it all out.

 

Regarding 1/2, line 5/6 of the code controls that. Look up the exponential randexp function to see how to set it with a specified mean. You probably want to switch to using the RAND() function instead which allows you to do this more easily. 

 

Regarding 3, look at line 4 of the code. What happens if you run the code as is. And then what happens when you change it and run it again?

 


@Buchholz91 wrote:

Buchholz91_0-1591810417218.png

 

Using the sample code above, how do I simulate survival data using certain specifications such as:

Buchholz91_1-1591810503864.png

 

My SAS skills are very rusty as I have not used it in over a year now. Any help would be greatly appreciated.


 

 

 

Buchholz91
Calcite | Level 5
data survData;
lambdat = 0.02; *baseline hazard;
lambdac = 0.04; *censoring hazard;
do i = 1 to 100;
t = RANEXP(12345)/lambdat; * time of event;
c = RANEXP(67890)/lambdac; * time of censoring;
time = min(t, c); * which happens first?;
censored = (c < t); * censored when the censoring hapapened before event;
output;
end;
drop i lambda:;

run;
proc freq data=SurvData;
tables censored ;
run;
proc univariate data=survData;
histogram T C;
run;

Above is the sample code that I have and below are a few questions. This is the same code & questions from earlier, but now they are copy and pasted instead of images.

simulate a survival data with the following specifications:

  • Event time T follows an exponential distribution with a mean of 40
  • Censoring time Tc follows an exponential distribution with a mean of 25
  • Generate 500 observations, with censoring flag indicating whether censoring happened before events.
Reeza
Super User
Did the suggestions not work for you? They should have answered your question, but the code posted just looks like your original code unless I'm missing something.
Buchholz91
Calcite | Level 5
I'm still in the process of trying to apply the suggestions that you made.
Currently trying to reintroduce myself to SAS after some time off and applying it in this way which I have not done before.

The code shown is still the same as before.
I'm assuming that I change the i = 1 to 100 to become i = 1 to 500 since I want to generate 500 observations.
Still trying to figure out how to specify a mean of 40.
I see that the Exponential Distribution is variable = RAND('Exponential', <sigma>).
Reeza
Super User

What's the expected value for an exponential distribution in relation to your parameter? That's a statistics question, not a programming question 🙂

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1313 views
  • 0 likes
  • 2 in conversation