SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ANKH1
Pyrite | Level 9

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

24 REPLIES 24
Reeza
Super User

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;
ANKH1
Pyrite | Level 9

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. 

ANKH1
Pyrite | Level 9

 This is the figure:

KM.jpg

Reeza
Super User

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. 

 

 

ANKH1
Pyrite | Level 9
Yes, last time observed is lastage. What does the y-axis "Failure probability" mean?
Reeza
Super User
That is the percentage of people hitting who've experienced the event.
ANKH1
Pyrite | Level 9

 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?

Reeza
Super User
Not necessarily, that was part of your question.
ANKH1
Pyrite | Level 9

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.

ANKH1
Pyrite | Level 9

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;
Reeza
Super User
If you run that does it work? I see syntax errors at minimum.
ANKH1
Pyrite | Level 9

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;
ANKH1
Pyrite | Level 9

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; 

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 24 replies
  • 2815 views
  • 0 likes
  • 2 in conversation