BookmarkSubscribeRSS Feed
Denali
Quartz | Level 8

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! 

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hi @Denali,

 

  1. Use the INSET statement to add the p-value:
    Extend the ODS OUTPUT statement:
    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.
  2. The group name belongs to keylegend 's'. Also, to avoid the collision mentioned above, you may want to combine the keylegends 's' and 'c' (and remove the separate KEYLEGEND statement for legend 'c').
    keylegend 's' 'c' / linelength=20 title="AKI";

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2929 views
  • 3 likes
  • 2 in conversation