Hi SAS community,
I used a long format of data and included four waves. And every two years had a wave. I plan to use proc phreg to do survival analysis and to calculate the survival time. How do I get survival time? I also did not know if ID 02 who did not get the disease should have 0 or 8 years of survival time.
Thanks for all your help!
ID | wave | Disease | expected results (survival time) |
01 | 1 | 0 | 6 |
01 | 2 | 0 | 6 |
01 | 3 | 0 | 6 |
01 | 4 | 1 | 6 |
02 | 1 | 0 | 8 or 0? |
02 | 2 | 0 | 8 or 0? |
02 | 3 | 0 | 8 or 0? |
02 | 4 | 0 | 8 or 0? |
03 | 1 | 0 | 2 |
03 | 2 | 1 | 2 |
03 | 3 | 1 | 2 |
03 | 4 | 1 | 2 |
So it sounds like you are accessing them at the BEGINNING of the 2 year period.
So the survivors should have a time of 6 years. At WAVE 5 you would know whether or not they survived 8 years.
You need to also keep the Disease variable (or something) to serve as your censoring variable for the survival analysis.
data want;
set have ;
by id wave;
retain censor time ;
if first.id then call missing(of censor time);
if missing(time) and Disease then do;
censor=0; time=2*(wave-1);
end;
if last.id then do;
if missing(time) then do; censor=1; time=2*(wave-1); end;
output;
end;
keep id censor time;
run;
Results:
Obs ID censor time 1 01 0 6 2 02 1 6 3 03 0 2
So it sounds like you are accessing them at the BEGINNING of the 2 year period.
So the survivors should have a time of 6 years. At WAVE 5 you would know whether or not they survived 8 years.
You need to also keep the Disease variable (or something) to serve as your censoring variable for the survival analysis.
data want;
set have ;
by id wave;
retain censor time ;
if first.id then call missing(of censor time);
if missing(time) and Disease then do;
censor=0; time=2*(wave-1);
end;
if last.id then do;
if missing(time) then do; censor=1; time=2*(wave-1); end;
output;
end;
keep id censor time;
run;
Results:
Obs ID censor time 1 01 0 6 2 02 1 6 3 03 0 2
I am sorry that I have a following up question. I found some participants who did no finish all these for waves. How could I deal with these people who did not participate in four waves?
ID | wave | Depression | expected results (survival time) |
01 | 1 | 0 | 6 |
01 | 2 | 0 | 6 |
01 | 3 | 0 | 6 |
01 | 4 | 1 | 6 |
02 | 1 | 0 | 8 |
02 | 2 | 0 | 8 |
02 | 3 | 0 | 8 |
02 | 4 | 0 | 8 |
03 | 1 | 0 | 2 |
03 | 2 | 1 | 2 |
03 | 3 | 1 | 2 |
03 | 4 | 1 | 2 |
04 | 1 | 0 | 2 |
04 | 2 | 0 | 2 |
05 | 1 | 0 | 2 |
05 | 2 | 1 | 2 |
05 | 3 | 1 | 2 |
06 | 1 | 0 | 8 |
06 | 3 | 0 | 8 |
06 | 4 | 0 | 8 |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.