- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, this is my first time attempting to run a KM curve in SAS. I apologize in advance if my questions are not well structured. We need to produce a KM curve for cumulative incidence from age at which subjects started treatment(Age_trt) to when they presented their first respiratory emergency (Event_age). This needs to be stratified by group1 and group2.
This is the raw dataset:
data have;
input ID Lastage group1 group2 Age_trt Event_age;
datalines;
1 12 0 1 2 4
2 13 0 1 4 6
3 11 1 0 3 7
4 12 1 0 2 .
5 14 0 1 2 .
6 12 1 0 7 9
7 11 1 0 1 6
8 14 0 1 3 .
9 13 1 0 3 .
10 13 0 1 5 8
;
run;
From what I gathered a "censored" variable is needed to run proc lifetest.
data for_test;
input ID Lastage group1 group2 Age_trt Event_age Censoring_status;
datalines;
1 12 0 1 4 1
2 13 0 1 6 1
3 11 1 0 7 1
4 12 1 0 . 0
5 14 0 1 . 0
6 12 1 0 9 1
7 11 1 0 6 1
8 14 0 1 . 0
9 13 1 0 . 0
10 13 0 1 8 1
;
run;
I am not sure how the group variable should be transformed and if so how. I am not sure how the code will need to be adapted to show the cumulative incidence instead of the more common survival analysis?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rough idea to get you started.
data have;
input ID Lastage group1 group2 Age_trt Event_age;
datalines;
1 12 0 1 2 4
2 13 0 1 4 6
3 11 1 0 3 7
4 12 1 0 2 .
5 14 0 1 2 .
6 12 1 0 7 9
7 11 1 0 1 6
8 14 0 1 3 .
9 13 1 0 3 .
10 13 0 1 5 8
;
run;
data sample;
set have;
time2event = coalesce(event_age, lastage) - age_trt;
censor = missing(event_age);
run;
proc format;
value group_label
0 = 'Group 2'
1 = 'Group 1';
run;
proc lifetest data=sample plots=survival(f);
strata group1;
format group1 group_label;
time time2event*censor(1);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rough idea to get you started.
data have;
input ID Lastage group1 group2 Age_trt Event_age;
datalines;
1 12 0 1 2 4
2 13 0 1 4 6
3 11 1 0 3 7
4 12 1 0 2 .
5 14 0 1 2 .
6 12 1 0 7 9
7 11 1 0 1 6
8 14 0 1 3 .
9 13 1 0 3 .
10 13 0 1 5 8
;
run;
data sample;
set have;
time2event = coalesce(event_age, lastage) - age_trt;
censor = missing(event_age);
run;
proc format;
value group_label
0 = 'Group 2'
1 = 'Group 1';
run;
proc lifetest data=sample plots=survival(f);
strata group1;
format group1 group_label;
time time2event*censor(1);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! For the group variables, basically we need only a variable called group to be able to stratify? And Lastage variable is needed to limit what? Sorry, I am having trouble interpreting the the graph and the use of the variable Lastage. Could you please show the figure you got and kindly explain the interpretation? It means appearance of the first event? Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is the figure:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First step is to create the time variable - specifically the time to event. Which I'm assuming is measured as the event_age - age_start treatment. However, for censored data you do not have an event, so to calculate time to event you use the last time observed, which I'm assuming is the lastAge.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Great! Thanks for explaining this. Just to confirm, for my knowledge, it is best to have a variable called group so this can be used to stratified right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok, how will the proc lifetest code change if you have a group variable and you want to stratify by this variable? Let's say the values are 1 and 2 for the group variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is this correct:
data sample;
set have;
time2event = coalesce(event_age, lastage) - age_trt;
censor = missing(event_age);
if group1=1 then group=1,
else group=2;
run;
proc lifetest data=sample plots=survival(f);
strata group;
time time2event*censor(1);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, missed a ";"
data sample;
set have;
time2event = coalesce(event_age, lastage) - age_trt;
censor = missing(event_age);
if group1=1 then group=1;
else group=2;
run;
proc lifetest data=sample plots=survival(f);
strata group;
time time2event*censor(1);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have another question, if we were to create a more elaborate figure using proc sgplot, we need a dataset from proc lifetest, correct?
I tried using this but it didn't work:
ods output survivalplot=sp;
proc lifetest data=sample plots=survival(f);
strata group;
time time2event*censor(1);
run;
ods output close;