Forked from statgeek/proc_lifetest_survival_plot.sas
Created
February 28, 2020 18:47
-
-
Save han-tun/a9431035ac2dfb5127f14268c8444993 to your computer and use it in GitHub Desktop.
Customize a SAS Survival Graph to display Months
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*SAS PROC LIFETEST Survival Plot Template | |
Modifed by: F. Khurshed | |
Date: July 27, 2011 | |
Description: I modified the basic GTL plot to | |
1) Changed the thickness of the lines plotted | |
2) Changed the X axis markers to 12 month intervals | |
3) Changed the Y axis markers to 0.25 level increments | |
4) Changed the label of the legend to be a macro variable called legend_label. This needs to be specified prior to output | |
5) Changed the Y axis markers to be formatted to percent using the tickvalueformat option. (2012-05-01 FK) | |
*/ | |
*Template appears in log; | |
proc template; | |
define statgraph Stat.Lifetest.Graphics.Productlimitsurvival; | |
dynamic NStrata xName plotAtRisk plotCensored plotCL plotHW plotEP labelCL labelHW labelEP maxTime method | |
StratumID classAtRisk plotBand plotTest GroupName yMin Transparency SecondTitle TestName pValue; | |
/*My Macro Variables*/ | |
mvar legend_label; | |
BeginGraph; | |
if (NSTRATA=1) | |
if (EXISTS(STRATUMID)) | |
entrytitle "Kaplan-Meier " "Survival Estimate" " for " STRATUMID; | |
else | |
entrytitle "Kaplan-Meier " "Survival Estimate"; | |
endif; | |
if (PLOTATRISK) | |
entrytitle "with Number of Subjects at Risk" / textattrs=GRAPHVALUETEXT; | |
endif; | |
layout overlay / xaxisopts=(shortlabel=XNAME offsetmin=.05 linearopts=(viewmax=MAXTIME /*Modifying X axis values here, need to change below as well*/ tickvaluelist=(0 12 24 36 48 60 72 84 96 108 120))) yaxisopts=(label= | |
"Survival Probability" shortlabel="Survival" linearopts=(viewmin=0 viewmax=1 tickvaluelist=(0 .25 .5 .75 | |
1.0) tickvalueformat=percent8.1 /*Modifying Y axis values here, need to change below as well*/)); | |
/*Add a reference line for the media*/ | |
*referenceline y=0.5/lineattrs=(color=red pattern=2); | |
if (PLOTHW=1 AND PLOTEP=0) | |
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / modelname="Survival" fillattrs=GRAPHCONFIDENCE | |
name="HW" legendlabel=LABELHW; | |
endif; | |
if (PLOTHW=0 AND PLOTEP=1) | |
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / modelname="Survival" fillattrs=GRAPHCONFIDENCE | |
name="EP" legendlabel=LABELEP; | |
endif; | |
if (PLOTHW=1 AND PLOTEP=1) | |
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / modelname="Survival" fillattrs=GRAPHDATA1 | |
datatransparency=.55 name="HW" legendlabel=LABELHW; | |
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / modelname="Survival" fillattrs=GRAPHDATA2 | |
datatransparency=.55 name="EP" legendlabel=LABELEP; | |
endif; | |
if (PLOTCL=1) | |
if (PLOTHW=1 OR PLOTEP=1) | |
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / modelname="Survival" display=(outline) | |
outlineattrs=GRAPHPREDICTIONLIMITS name="CL" legendlabel=LABELCL; | |
else | |
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / modelname="Survival" fillattrs=GRAPHCONFIDENCE | |
name="CL" legendlabel=LABELCL; | |
endif; | |
endif; | |
stepplot y=SURVIVAL x=TIME / name="Survival" rolename=(_tip1=ATRISK _tip2=EVENT) tip=(y x Time _tip1 | |
_tip2) legendlabel="Survival" lineattrs=(thickness=2); | |
if (PLOTCENSORED=1) | |
scatterplot y=CENSORED x=TIME / markerattrs=(symbol=plus size=8px) name="Censored" legendlabel="Censored"; | |
endif; | |
if (PLOTCL=1 OR PLOTHW=1 OR PLOTEP=1) | |
discretelegend "Censored" "CL" "HW" "EP" / location=outside halign=center; | |
else | |
if (PLOTCENSORED=1) | |
discretelegend "Censored" / location=inside autoalign=(topright bottomleft); | |
endif; | |
endif; | |
if (PLOTATRISK=1) | |
innermargin / align=bottom; | |
blockplot x=TATRISK block=ATRISK / repeatedvalues=true display=(values) valuehalign=start | |
valuefitpolicy=truncate labelposition=left labelattrs=GRAPHVALUETEXT valueattrs=GRAPHDATATEXT (size | |
=7pt) includemissingclass=false ; | |
endinnermargin; | |
endif; | |
endlayout; | |
else | |
entrytitle "Kaplan-Meier " "Survival Estimates"; | |
layout overlay / xaxisopts=(shortlabel=XNAME offsetmin=.05 linearopts=(viewmax=MAXTIME tickvaluelist=(0 12 24 36 48 60 72 84 96 108 120) /*Modifying the X values on graph here, need to change above as well*/)) yaxisopts=(label= | |
"Survival Probability" shortlabel="Survival" linearopts=(viewmin=0 viewmax=1 tickvaluelist=(0 .25 .5 .75 | |
1.0) tickvalueformat=percent8.1 /*Modifying the Y Axis values here, need to change above as well*/)); | |
/*Add a reference line for the media*/ | |
*referenceline y=0.5/lineattrs=(color=red pattern=2); | |
if (PLOTHW) | |
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / group=STRATUM index=STRATUMNUM modelname= | |
"Survival" datatransparency=Transparency; | |
endif; | |
if (PLOTEP) | |
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / group=STRATUM index=STRATUMNUM modelname= | |
"Survival" datatransparency=Transparency; | |
endif; | |
if (PLOTCL) | |
if (PLOTBAND) | |
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / group=STRATUM index=STRATUMNUM modelname= | |
"Survival" display=(outline); | |
else | |
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / group=STRATUM index=STRATUMNUM modelname= | |
"Survival" datatransparency=Transparency; | |
endif; | |
endif; | |
stepplot y=SURVIVAL x=TIME / group=STRATUM index=STRATUMNUM name="Survival" rolename=(_tip1=ATRISK _tip2= | |
EVENT) tip=(y x Time _tip1 _tip2) lineattrs=(thickness=2); | |
if (PLOTCENSORED) | |
scatterplot y=CENSORED x=TIME / group=STRATUM index=STRATUMNUM markerattrs=(symbol=plus size=8px); | |
endif; | |
if (PLOTATRISK) | |
innermargin / align=bottom; | |
blockplot x=TATRISK block=ATRISK / class=STRATUM repeatedvalues=true display=(label values) | |
valuehalign=start valuefitpolicy=truncate labelposition=left labelattrs=STRATUMID valueattrs= | |
GRAPHDATATEXT (size=7pt) includemissingclass=false; | |
endinnermargin; | |
endif; | |
DiscreteLegend "Survival" / title=legend_label location=outside; | |
if (PLOTCENSORED) | |
if (PLOTTEST) | |
layout gridded / rows=2 autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM) border=false BackgroundColor= | |
GraphWalls:Color Opaque=true; | |
entry "+ Censored"; | |
if (PVALUE < .0001) | |
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4)); | |
else | |
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4)); | |
endif; | |
endlayout; | |
else | |
layout gridded / rows=1 autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM) border=false BackgroundColor= | |
GraphWalls:Color Opaque=true; | |
entry "+ Censored"; | |
endlayout; | |
endif; | |
else | |
if (PLOTTEST) | |
layout gridded / rows=1 autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM) border=false BackgroundColor= | |
GraphWalls:Color Opaque=true; | |
if (PVALUE < .0001) | |
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4)); | |
else | |
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4)); | |
endif; | |
endlayout; | |
endif; | |
endif; | |
endlayout; | |
endif; | |
EndGraph; | |
end; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment