BookmarkSubscribeRSS Feed
tbn1
Calcite | Level 5

How can I change the X axis in a CIF plot? It seems to only work for survival plots. 

 

Thanks!

23 REPLIES 23
Reeza
Super User

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!


 

tbn1
Calcite | Level 5

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;

JeffMeyers
Barite | Level 11

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). 

tbn1
Calcite | Level 5
Hi Jeff,

I created this:
%macro 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);
%mend newsurv;

But then do I use proc lifetest plots=cif (Test) to plot this? That did not change anything

%macro 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);
%mend newsurv;
JeffMeyers
Barite | Level 11

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);

JeffMeyers
Barite | Level 11
I also just saw for CLASSORDER you want to specify the order in a list greater than 1 where the numbers correspond to the alphabetical order of your CLASS variable values. having 0 1 will give an error, so you'd want to do something like CLASSORDER=1 2 or CLASSORDER=2 1.
tbn1
Calcite | Level 5

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?

JeffMeyers
Barite | Level 11
That is correct. You have to initialize the macro in order to call it later. When you do run your version with your specific parameters you only need to input the ones you are changing, don't worry about running every parameter listed in the macro call. What you posted earlier will be enough to run the macro.
tbn1
Calcite | Level 5
I tried this and nothing happened?
%macro newsurv(DATA=, TIME=, CENS=0, CEN_VL=0, SUMMARY=, CLASSS=, CLASSREF=,CLASSORDER=, COLOR=blue red, PATTERN=solid, LINESIZE=6pt, SYMBOLSIZE=10pt, XMAX=5, XINCREMENT=1, XLABEL=Months, YLABEL=Recurrence Risk, METHOD=CIF, EV_VL=1);
%mend newsurv;
%newsurv(DATA=adj2, TIME=Time_After_Surgery__Years__1, CENS=0, CEN_VL=0, SUMMARY=0, CLASSS=adj, CLASSREF=1,CLASSORDER=1 2, COLOR=blue red, PATTERN=solid, LINESIZE=6pt, SYMBOLSIZE=10pt, XMAX=5, XINCREMENT=1, XLABEL=Months, YLABEL=Recurrence Risk, METHOD=CIF, EV_VL=1);

Thank you SO much for your help
JeffMeyers
Barite | Level 11

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.

Reeza
Super User

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.

 

http://documentation.sas.com/?docsetId=statug&docsetTarget=statug_kaplan_toc.htm&docsetVersion=14.3&...

 

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.

http://documentation.sas.com/?docsetId=statug&docsetTarget=statug_templt_sect001.htm&docsetVersion=1...

 

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. 

 

 

tbn1
Calcite | Level 5

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?

 

Reeza
Super User
Not AFAIK, ergo the recommendation to save a back up copy.
tbn1
Calcite | Level 5

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.

SAS Innovate 2025: Register Now

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!

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
  • 23 replies
  • 6212 views
  • 2 likes
  • 3 in conversation