BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ammarhm
Lapis Lazuli | Level 10

I have noticed a strange behaviour when requesting a stratified hazard plot from proc lifetest. 

To illustrate the problem, I have used the code and dataset from the following website:

https://stats.oarc.ucla.edu/sas/seminars/sas-survival/

 

Specially, the code below should result in a stratified hazard plot as shown in the website:

proc lifetest data=whas500 atrisk plots=hazard(bw=200) outs=outwhas500;
strata bmi(15,18.5,25,30,40);
time lenfol*fstat(0);
run;

However, the plot generated is a series of connected lines, and is not stratified and does not look like the on tin the website:

HazardPlot1.png

 

I have tested this on multiple datasets with the same result, the lines are connected and not stratified. 

I tested this on SAS 9.4 and on SAS EG 8.1 with the same result!

Any other analysis, such as a stratified Kaplan Meier works perfectly fine but for hazard plots the graphs just don't look right.

Could anyone please test this and let me know if they get similar results and maybe suggest a solution?

kind regards

Am

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

When I run your example on SAS 9.4M6, I get the following output:

 

Rick_SAS_0-1641224242961.png

 

What version of SAS are you running? Submit
%put &=SYSVLONG;
and post the output that appears in the log.

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

When I run your example on SAS 9.4M6, I get the following output:

 

Rick_SAS_0-1641224242961.png

 

What version of SAS are you running? Submit
%put &=SYSVLONG;
and post the output that appears in the log.

 

ammarhm
Lapis Lazuli | Level 10

Thanks @Rick_SAS 

Here is the output you requested: 

SYSVLONG=9.04.01M6P110718

I think I have found the cause of the problem, I have made some changes to Stat.Lifetest.Graphics.SmoothedHazard using proc template. I went back and deleted this template to restore defaults and re-ran the code and the output looks fine now. 

This is the code I used initially to manipulate the template:

 

proc template;
    delete Stat.Lifetest.Graphics.ProductLimitSurvival  / store=sasuser.templat;
    delete Stat.Lifetest.Graphics.ProductLimitSurvival2 / store=sasuser.templat;
	delete Stat.Lifetest.Graphics.SmoothedHazard / store=sasuser.templat;
	delete Stat.Lifetest.Graphics.SmoothedHazard2 / store=sasuser.templat;
run;

proc template;
source  Stat.Lifetest.Graphics.SmoothedHazard;
define statgraph Stat.Lifetest.Graphics.SmoothedHazard;
   dynamic NStrata Kernel Bandwidth confLimits GroupName maxTime _byline_ _bytitle_ _byfootnote_;
   BeginGraph;
         entrytitle  "";
         layout overlay / yaxisopts=(label="Estimated Hazard Rate" shortlabel="Hazard") xaxisopts=(linearopts=(viewmax=MAXTIME));
            bandplot LimitUpper=UPPER LimitLower=LOWER x=TIME / displayTail=false modelname="Hazard" name="Confidence" LegendLabel=
               CONFLIMITS;
            seriesplot y=HAZARD x=TIME / name="Hazard";
         endlayout;
   EndGraph;
end;
run;

 

 

I did not deal with NSRATA >1 and group=STRATUM correctly in the template, I should have done it this way:

 

 

BeginGraph;
      if (NSTRATA=1)
         entrytitle "";
         layout overlay / yaxisopts=(label="Estimated Hazard Rate" shortlabel="Hazard") xaxisopts=(linearopts=(viewmax=MAXTIME));
            bandplot LimitUpper=UPPER LimitLower=LOWER x=TIME / displayTail=false modelname="Hazard" name="Confidence" LegendLabel=
               CONFLIMITS;
            seriesplot y=HAZARD x=TIME / name="Hazard";
            if (EXISTS(CONFLIMITS))
               DISCRETELEGEND "Confidence" / location=outside halign=center valign=bottom;
            endif;
         endlayout;
      else
         entrytitle "";
         entrytitle CONFLIMITS / textattrs=GRAPHVALUETEXT;
         layout overlay / yaxisopts=(label="Estimated Hazard Rate" shortlabel="Hazard") xaxisopts=(linearopts=(viewmax=MAXTIME));
            bandplot LimitUpper=UPPER LimitLower=LOWER x=TIME / displayTail=false group=STRATUM index=STRATUMNUM modelname="Hazard"
               display=standard datatransparency=.5;
            if (EXISTS(MAXTIME))
               seriesplot y=HAZARD x=TIME / name="Hazard" group=STRATUM index=STRATUMNUM curvelabel=BANDWIDTHLABEL
                  curvelabellocation=inside curvelabelposition=start;
            else
               seriesplot y=HAZARD x=TIME / name="Hazard" group=STRATUM index=STRATUMNUM curvelabel=BANDWIDTHLABEL
                  curvelabellocation=inside curvelabelposition=end;
            endif;
             discretelegend "Hazard" / title=GROUPNAME location=outside hAlign=center vAlign=bottom;
         endlayout;
      endif;
      if (_BYTITLE_)
         entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
      else
         if (_BYFOOTNOTE_)
            entryfootnote halign=left _BYLINE_;
         endif;
      endif;
   EndGraph;
end;                           

Now it is working correctly. Your output figure (the presence of the entry title "Epanechinkov Kernel-Smoothed Hazard Function") gave me the hint and reminded me of the cause

 

Thanks again. 

 

 

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 727 views
  • 3 likes
  • 2 in conversation