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;
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;
When using the EVENTCODE= option for a competing risks analysis PROC LIFETEST does not support the ATRISK plot option.
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;
This is great!
Thank you
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:
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.
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?
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;
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;
Hope you can see the sample.csv file. Thank you!
I just ran your code and it worked! Thank you so much!!!
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!
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.