Hi,
I made a Kaplan-Meier plot using proc sgplot. Please see attached graph.
Below are my 2 questions:
1. How to add "log rank p value" under "+Censor"?
2. I also tried to add "AKI" as my group name for the legend (before No ----- and Yes ----)-
I thougt the adding" label stratum = AKI;" or "keylegend 'No' 'Yes' / title="AKI"; " but it did not.
Below is the SAS code:
/*--Get survival plot data from LIFETEST procedure--*/
ods select none;
ods output Survivalplot=SurvivalPlotData;
proc lifetest data=two plots=survival(atrisk=5 to 20 by 2.5);
time Survive_year * death(0);
strata AKI;
run;
ods select all;
/*--Survival Plot with outer Risk Table using AxisTable--*/
ods graphics / reset width=5in height=3in ;
title 'Product-Limit Survival Estimates';
title2 h=0.8 'With Number of Subjects at Risk';
ods listing gpath= "H:\Biostatistics\Ihsin\Subspecialty Medicine\Renal Service\Latcha,Sheron\SAS Program" image_dpi=300 ;
ods graphics on/ imagefmt = tiff imagename = "Figure_AKI_Survivor_5yr" reset = index;
proc sgplot data=SurvivalPlotData noborder;
step x=time y=survival / group=stratum name='s';
scatter x=time y=censored / markerattrs=(symbol=plus) name='c';
scatter x=time y=censored / markerattrs=(symbol=plus) GROUP=stratum;
xaxistable atrisk / x=tatrisk location=inside class=stratum colorgroup=stratum valueattrs=(weight=bold);
keylegend 'c' / location=inside position=topright;
keylegend 's' / linelength=20;
keylegend 'No' 'Yes' / title="AKI";
*controls the graph axis;
xaxis values=(5 to 20 by 5);
yaxis values=(0 to 1 by .2);
label time = Time (Year) stratum = AKI;
run;
Thanks in advance!
Hi @Denali,
ods output Survivalplot=SurvivalPlotData HomTests=LogRank(where=(test='Log-Rank'));
Store the (formatted) p-value in a macro variable:data _null_;
set LogRank;
call symputx('pval',put(probchisq,pvalue.));
run;
Add the INSET statement to the PROC SGPLOT step:inset ("Log-Rank p-value"="&pval") / border position=topright;
Currently, this will collide with the keylegend 'c' (alternative: use position=right), but see item 2 below.keylegend 's' 'c' / linelength=20 title="AKI";
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.