I am able to display 95% Hall-Wellner Confidence bands in my lifetest procedure and want to keep them on the graph, but want to remove the legend at the bottom of the graph that says "95% Hall-Wellner Band"
I know that when I separate by strata this legend disappears, but when only one strata is displayed this lable/legend is present.
Here is my lifetest code if helpful:
proc lifetest data=file plots=survival (cb nocensor atrisk=0 to 22.5 by 2.5);
time OS_time_KM*vitalstatusOS_KM(1);
run;
Is there a line of code in the %macro ProvideSurvivalMacros from the "Customizing the Kaplan-Meier Survival Plot" chapter?
Thanks for the help!
Well, there might be a way to do it with the macros, but I'm really busy today so here is the manual way to get what you want:
1. Display the template with the current modifications:
proc template;
source Stat.Lifetest.Graphics.ProductLimitFailure;
quit;
2. Copy the source into a program editor.
3. Find the line that says
discretelegend "Censored" "CL" "HW" "EP" / location=outside halign=center;
and edit it to remove the HW name, like this:
discretelegend "Censored" "CL" /* "HW" */ "EP" / location=outside halign=center;
4. Save the template by running the following:
proc template;
define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival;
dynamic NStrata xName plotAtRisk plotCensored plotCL plotHW plotEP labelCL labelHW labelEP maxTime xtickVals xtickValFitPol
rowWeights method StratumID classAtRisk plotTest GroupName Transparency SecondTitle TestName pValue _byline_ _bytitle_
_byfootnote_;
BeginGraph;
ETC...PASTE REST OF SOURCE HERE, INCLUDING CHANGES
EndGraph;
end;
run;
5. Now run PROC LIFETEST and the HW bands will not appear in the legend.
Yes that is in my code %let LegendOpts = ; doesn't appear to suppress the legend label from the confidence bands in a single stratum
Here are my macro adjustments
%ProvideSurvivalMacros
%let TitleText0 = " " ; /* Change the title. */
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0;
%let ntitles = 1;
%let yOptions = label="Overall Survival Probability (%)"
linearopts=(viewmin=0 viewmax=1.0
tickvaluelist=(0 .25 .50 .75 1.00)
tickvalueformat = PERCENTN10.); *converts tickvalues to percent;
%let GraphOpts = DesignHeight = 550px;
%let InsetOpts = ;
%let LegendOpts = ;
%let StepOpts = lineattrs=(thickness=2.5);
%CompileSurvivalTemplates;
Well, there might be a way to do it with the macros, but I'm really busy today so here is the manual way to get what you want:
1. Display the template with the current modifications:
proc template;
source Stat.Lifetest.Graphics.ProductLimitFailure;
quit;
2. Copy the source into a program editor.
3. Find the line that says
discretelegend "Censored" "CL" "HW" "EP" / location=outside halign=center;
and edit it to remove the HW name, like this:
discretelegend "Censored" "CL" /* "HW" */ "EP" / location=outside halign=center;
4. Save the template by running the following:
proc template;
define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival;
dynamic NStrata xName plotAtRisk plotCensored plotCL plotHW plotEP labelCL labelHW labelEP maxTime xtickVals xtickValFitPol
rowWeights method StratumID classAtRisk plotTest GroupName Transparency SecondTitle TestName pValue _byline_ _bytitle_
_byfootnote_;
BeginGraph;
ETC...PASTE REST OF SOURCE HERE, INCLUDING CHANGES
EndGraph;
end;
run;
5. Now run PROC LIFETEST and the HW bands will not appear in the legend.
Just going to make a plug for my survival graphing macro that I've shared on here: https://communities.sas.com/t5/SAS-Communities-Library/Kaplan-Meier-Survival-Plotting-Macro-NEWSURV/...
Maybe you'll find it helpful.
It has all sorts of features for survival graphs. I think you could make your graph with the following macro call:
%newsurv(data=file, time=os_time_km, cens=vitalstatusos_km, cen_vl=1, summary=0, display=, risklist=0 to 22.5 by 2.5, risklocation=inside, ylabel=Overall Survival Probability (%), yincrement=25, classdesc=At Risk, parheader=, riskdivider=0, height=550px, linesize=2.5, censormarkers=0)
;
thanks will give this a try in my next round of KM curves!
If you think you will need to make this change more than once, you can automate it by using Steps 1-4 of Kuhfeld's template modification technique. See "A SAS programming technique to modify ODS templates"
Instead of Step 5, you will run PROC LIFETEST.
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.