BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jtepe93
Calcite | Level 5

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!

 

 

I want to keep the bands, but the delete the legend/labelI want to keep the bands, but the delete the legend/label

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

6 REPLIES 6
Rick_SAS
SAS Super FREQ

Did you try the steps in the section "Suppressing the Legend"?

%let LegendOpts = ;

 

jtepe93
Calcite | Level 5

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;

Rick_SAS
SAS Super FREQ

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.

JeffMeyers
Barite | Level 11

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)

 

 

;

jtepe93
Calcite | Level 5

thanks will give this a try in my next round of KM curves!

Rick_SAS
SAS Super FREQ

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-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4233 views
  • 1 like
  • 3 in conversation