BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lih
Calcite | Level 5 lih
Calcite | Level 5

How to plot cumulative incidence with number at risk from survival analysis with competing risk (see code below) 

 

ods graphics on;
proc lifetest data=dataname plots=cif(test ) notable timelist=0 6 12 18 24 36 48 60 OUTCIF=cifnrm_out;
time time*event(0)/eventcode=1;
strata group/order=internal;
run;
ods graphics off;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You want this ?

proc lifetest data=sashelp.bmt plots=cif(test ) notable  OUTCIF=cifnrm_out ;
time t*status(0)/eventcode=1;
strata group/order=internal;
run;



data time;
do t=0 to 2500 by 500;
 output;
end;
run;
proc sql;
create table temp as
select * from (select distinct Group from cifnrm_out),time order by 1,2;
quit;
data want;
 set cifnrm_out temp(in=inb);
 by Group t;
 retain temp;
 if first.Group then call missing(temp);
 if not missing(AtRisk) then temp=AtRisk;
 if inb then time_AtRisk=temp;
 keep Group t AtRisk CIF time_AtRisk ;
run;
options missing=' ';
proc sgplot data=want;
step x=T y=CIF/group=Group;
xaxistable time_AtRisk/class=group colorgroup=Group location=inside;
xaxis label='Disease-Free Survival Time';
yaxis values=(0 to 1 by 0.2);
run;

Ksharp_0-1731120144011.png

 

View solution in original post

14 REPLIES 14
OsoGris
SAS Employee

When using the EVENTCODE= option for a competing risks analysis PROC LIFETEST does not support the ATRISK plot option.

Ksharp
Super User

You want this ?

proc lifetest data=sashelp.bmt plots=cif(test ) notable  OUTCIF=cifnrm_out ;
time t*status(0)/eventcode=1;
strata group/order=internal;
run;



data time;
do t=0 to 2500 by 500;
 output;
end;
run;
proc sql;
create table temp as
select * from (select distinct Group from cifnrm_out),time order by 1,2;
quit;
data want;
 set cifnrm_out temp(in=inb);
 by Group t;
 retain temp;
 if first.Group then call missing(temp);
 if not missing(AtRisk) then temp=AtRisk;
 if inb then time_AtRisk=temp;
 keep Group t AtRisk CIF time_AtRisk ;
run;
options missing=' ';
proc sgplot data=want;
step x=T y=CIF/group=Group;
xaxistable time_AtRisk/class=group colorgroup=Group location=inside;
xaxis label='Disease-Free Survival Time';
yaxis values=(0 to 1 by 0.2);
run;

Ksharp_0-1731120144011.png

 

J_Park
Calcite | Level 5

This is great info to create the plot including number of risk.  I followed the steps but in the end, I only got this (attached).  No numbers shown.  I am not sure why.  Any insights?

Thank you!

SAS Code I used:

 
proc sgplot data=test;
step x=timeBDD_3 y=CIF/group=pred_opt_ter;
xaxistable time_AtRisk/class=pred_opt_ter colorgroup=pred_opt_ter location=inside;
     xaxis values=(0 to 3.25 by 0.5) labelattrs=(size=13) valueattrs=(size=13)  ;  
     yaxis  values=(0 to 0.2 by 0.05) label= "Probability" labelattrs=(size=13) valueattrs=(size=13);
xaxis label='Years';
keylegend  /  title='Predicted Probability' location=outside position=bottom across=3  valueattrs=(size=12) TITLEATTRS=(size=12); 
    title h=12pt 'Probability of MACE by Optimal CT Predicted Probability Tertiles';    
format pred_opt_ter gp.;
run;

 

Ksharp
Super User
Plz post your sample data,so I can test it .
And post your FULL code, you should notice that I have one more data step to get the number of risk before PROC SGPLOT ,but you didn't post it yet.
J_Park
Calcite | Level 5
Hello,
This is the full sas code I used.  I was able to add the number at risk but they are identical across the time.   I can't figure out why.   I would appreciate any insights.   The data attached is a mock up data as I can't send the actual data.
Thank you!JP

data model1_tert2(keep= T Group eventstatus );  set model1_tert ;     rename         timeBDD_3 = T        pred_opt_ter = Group          eventBDD_3 = eventstatus;  run;

proc lifetest data=model1_tert2  plots=cif(test ) notable  OUTCIF=cifnrm_out ;     time T*eventstatus(0)/eventcode=1;  strata Group/order=internal; run;

data time;do t=0 to 3.0 by 0.5; output;end;run;
proc sql;create table temp asselect * from (select distinct Group from cifnrm_out),time order by 1,2;quit;
data test; set cifnrm_out temp(in=inb); by Group ; retain temp; if first.Group then call missing(temp); if not missing(AtRisk) then temp=AtRisk; if inb then time_AtRisk=temp; keep Group T AtRisk CIF time_AtRisk ;run;

proc format ; value group0   = "<0.02"1   = "0.02-0.03"2   = ">0.03";quit;

options missing=' ';
proc sgplot data=test noborder;styleattrs datacontrastcolors=(green blue darkred);   step x=T y=cif /  group=group name='plaque'  lineattrs=(thickness=4 pattern = SOLID) ;   keylegend 'plaque' /  title='Predicted Probability' location=outside position=bottom across=3  valueattrs=(size=12) TITLEATTRS=(size=12);
  xaxistable time_AtRisk/class=group colorgroup=group location=inside;    * xaxis values=(0 to 3.25 by 0.5) labelattrs=(size=13) valueattrs=(size=13)  ;  xaxis min=0 max=3.25 values=(0 0.5 1.0 1.5 2.0 2.5 3.0 )           labelattrs=(size=13)           valueattrs=(size=13);      yaxis  values=(0 to 0.2 by 0.05) label= "Probability" labelattrs=(size=13) valueattrs=(size=13);    xaxis label='Years';    label T =  "Years"   cif= "MACE";      title h=12pt 'Probability of MACE by Optimal CT Predicted Probability Tertiles';     format group group.;run;
Ksharp
Super User
"The data attached is a mock up data as I can't send the actual data."
Where is your dataset? I don't see any attachment.
Ksharp
Super User

With using the builded-in sas dataset SASHELP.BMT as a sample dataset to test your code.

I think I found where the problem is:

You missed T variable in your code,check my original code.

data model1_tert2(keep= T Group eventstatus ); 
set sashelp.bmt;
rename status=eventstatus;
run;

proc lifetest data=model1_tert2  plots=cif(test ) notable  OUTCIF=cifnrm_out ;    
time T*eventstatus(0)/eventcode=1;  
strata Group/order=internal; 
run;

data time;
/*do t=0 to 3.0 by 0.5; */
do t=0 to 2500 by 500;
output;
end;
run;

proc sql;
create table temp as
select * from (select distinct Group from cifnrm_out),time
order by 1,2;
quit;

data test; 
set cifnrm_out temp(in=inb); 
by Group T;   /* <------- You missed the T variable*/
retain temp; 
if first.Group then call missing(temp); 
if not missing(AtRisk) then temp=AtRisk; 
if inb then time_AtRisk=temp; 
keep Group T AtRisk CIF time_AtRisk ;
run;

Open dataset TEST,you could see the different value from different T.

Ksharp_0-1734659936255.png

 

 

J_Park
Calcite | Level 5

OMG, I feel so stupid.  how can I miss the "T"?  Thank you soooooo much for your help!!!  Now it works great except one thing.  I wanted the xaxis values=(0 to 3.25 by 0.5) but it only shows 0, 1, 2, and 3.  I am not sure why.  Any insights?   

Ksharp
Super User

Then plz post the sample dataset , so I think test it .

Still using sas built-in dataset sashelp.bmt to test,and still not found any problem .

Referring to the following code,maybe you could found where the problem is by yourself.

proc lifetest data=sashelp.bmt plots=cif(test ) notable  OUTCIF=cifnrm_out ;
time t*status(0)/eventcode=1;
strata group/order=internal;
run;



data time;
do t=0 to 2500 by 100;
 output;
end;
run;
proc sql;
create table temp as
select * from (select distinct Group from cifnrm_out),time order by 1,2;
quit;
data want;
 set cifnrm_out temp(in=inb);
 by Group t;
 retain temp;
 if first.Group then call missing(temp);
 if not missing(AtRisk) then temp=AtRisk;
 if inb then time_AtRisk=temp;
 keep Group t AtRisk CIF time_AtRisk ;
run;
options missing=' ';
proc sgplot data=want;
step x=T y=CIF/group=Group;
xaxistable time_AtRisk/class=group colorgroup=Group location=inside;
xaxis label='Disease-Free Survival Time' values=(0 to 2500 by 100) fitpolicy=stagger; /*fitpolicy=none*/
yaxis values=(0 to 1 by 0.2);
run;

Ksharp_0-1734763356835.png

 

J_Park
Calcite | Level 5
Hello,
Thank you again for your response!    I am attaching my code and the sample file.    Thank you so much for your help!

proc lifetest data=sample  plots=cif(test ) notable  OUTCIF=cifnrm_out ;     time T*eventstatus(0)/eventcode=1;strata Group/order=internal; run;

proc freq data = cifnrm_out;tables  group*event group*censored;run;

data time;do t=0 to 3.0 by 0.5; output;end;run;
proc sql;create table temp asselect * from (select distinct Group from cifnrm_out),time order by 1,2;quit;
data test; set cifnrm_out temp(in=inb); by Group t; retain temp; if first.Group then call missing(temp); if not missing(AtRisk) then temp=AtRisk; if inb then time_AtRisk=temp; keep Group t AtRisk CIF time_AtRisk ;run;
proc freq data = test;tables  group*time_atrisk;run;


proc format ; value gp0   = "<0.02"1   = "0.02-0.03"2   = ">0.03";quit;
options missing=' ';
proc sort data=test; by descending group; run;
proc sgplot data=test noborder;styleattrs datacontrastcolors=(darkred blue green);  step x=T y=cif /  group=group name='plaque'  lineattrs=(thickness=4 pattern = SOLID) ;   keylegend 'plaque' /  title='Predicted Probability' location=outside position=bottom across=3  valueattrs=(size=12) TITLEATTRS=(size=12);
  xaxistable time_AtRisk/class=group colorgroup=group location=inside;    xaxis values=(0 to 3 by 0.5) labelattrs=(size=13) valueattrs=(size=13)  ;        yaxis  values=(0 to 0.2 by 0.05) label= "Probability" labelattrs=(size=13) valueattrs=(size=13);    xaxis label='Years';    label T =  "Years"   cif= "MACE";     title h=12pt 'Probability of MACE by Optimal CT Predicted Probability Tertiles';    format group gp.;run;

Ksharp
Super User

Where is your attachment for SAMPLE dataset?

And I noticed that you have TWO xaxis statements,why ? I think you should remove the second xaxis statement.

proc sgplot data=test noborder;
styleattrs datacontrastcolors=(darkred blue green);  
step x=T y=cif /  group=group name='plaque'  lineattrs=(thickness=4 pattern = SOLID) ;   
keylegend 'plaque' /  title='Predicted Probability' location=outside
                     position=bottom across=3  valueattrs=(size=12) TITLEATTRS=(size=12);

xaxistable time_AtRisk/class=group colorgroup=group location=inside;   
xaxis values=(0 to 3 by 0.5) labelattrs=(size=13) valueattrs=(size=13)  fitpolicy=none  label='Years'   ;     
yaxis  values=(0 to 0.2 by 0.05) label= "Probability" labelattrs=(size=13) valueattrs=(size=13);   
/* xaxis label='Years';    <--- Should get rid of it*/
label T =  "Years"   cif= "MACE";     
title h=12pt 'Probability of MACE by Optimal CT Predicted Probability Tertiles';   
format group gp.;
run;

 

J_Park
Calcite | Level 5

Hope you can see the sample.csv file.  Thank you!

J_Park
Calcite | Level 5

I just ran your code and it worked!   Thank you so much!!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is ANOVA?

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.

Discussion stats
  • 14 replies
  • 1120 views
  • 1 like
  • 4 in conversation