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:
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
When I run your example on SAS 9.4M6, I get the following output:
What version of SAS are you running? Submit
%put &=SYSVLONG;
and post the output that appears in the log.
When I run your example on SAS 9.4M6, I get the following output:
What version of SAS are you running? Submit
%put &=SYSVLONG;
and post the output that appears in the log.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.