How can I change the X axis in a CIF plot? It seems to only work for survival plots.
Thanks!
Code/log?
What version of SAS are you using? I'm assuming you're using PROC PHREG for competing risks?
PS. Replying to a 2years+ thread isn't going to get a response, but it helps if you link to it in your post.
@tbn1 wrote:
How can I change the X axis in a CIF plot? It seems to only work for survival plots.
Thanks!
Hi Reeza,
I am new to this - was trying to respond to your post from 2 years ago. I am using SAS 9.4
I have copied and pasted the response below. I used this code to format my survival curves in proc lifetest and change the axes.
Currently, I am trying to compare and plot competing risks (recurrence) between 2 groups.
Have been using this code:
proc phreg data=bmt plots(overlay=strata)=cif;
class Group / param=glm order=internal ref=first;
model T*Status(0) = Group logWaitTime / eventcode=1;
baseline covariates=risk out=_null_ / rowid=Group;
run;
(from https://support.sas.com/rnd/app/stat/papers/2014/competingrisk2014.pdf)
Thanks!
Formatting from your previous post:
/*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;
Hello, If you want an easy way to make CIF curves and have options to change them I'd suggest trying my macro %NEWSURV. You can find the macro and examples here:
http://www.sascommunity.org/wiki/Kaplan-Meier_Survival_Plotting_Macro_%25NEWSURV
Check out example 6 (and the other examples).
Hello, The macro itself makes the plot based on a GTL template it makes within the macro.
When you run the macro do not include the %macro and %mend. First run the entire macro code %macro to the %mend from the website, or save it as a program and then %include it.
Then run your macro call like this:
%newsurv(DATA=adj, TIME= Time_After_Surgery__Years__1, CENS=recur, CEN_VL=0, SUMMARY=0, CLASS=DIAGNOSIS, CLASSREF=0,CLASSORDER=0 1, COLOR=blue red, PATTERN=solid, LINESIZE=3pt, SYMBOLSIZE=10pt, XMAX=5, XINCREMENT=1, XLABEL=Months, YLABEL=Recurrence Risk, METHOD=CIF, EV_VL=1);
Sorry to ask silly questions but I have not done this before. So I run it without my specific data first (with the generic terms on website), then I call it with specifics?
Do not include %macro in front of the macro. Only %newsurv(....).
You will potentially to close and reopen your sas session because it thinks you are defining %newsurv (since you don't have a %mend). Only use %macro when defining a macro, when you call the macro just use %macroname.
The code in that post won't work for a CIF plot, you'd need to find a different approach.
Also, since then, SAS has released several macros the control the appearance of survival curves, which is much easier than the solution from a few years ago.
For PROC PHREG, you need to first find the template and then modify it manually.
This walks you through how to first find your template and then how to modify what you need. Note that there's a section of examples as well, but this is generic for any ODS proc.
If you're having trouble getting it to work, post back with details of what steps you've take and what is/isn't working.
Also, be careful. You can destroy your template and then it's broken forever, so make sure to save a back up somewhere.
Hi Reeza,
Thanks for this information.
Is there a way to reset to the default template for Stat.Phreg.Graphics.CIF if I messed something up?
Thanks - I was playing with your old code before I knew what I was doing and I think I changed it already so I do not have the original template.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.