- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When using the EVENTCODE= option for a competing risks analysis PROC LIFETEST does not support the ATRISK plot option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is great!
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Where is your dataset? I don't see any attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hope you can see the sample.csv file. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I just ran your code and it worked! Thank you so much!!!