BookmarkSubscribeRSS Feed
Anna_h
Calcite | Level 5

http://support.sas.com/documentation/onlinedoc/stat/ex_code/121/

 

Hi there, I am using this template to output population at risk along the x-axis (see attached). It seems only go up to 15 months. Does anyone have a template allow longer duration like up to 80 months? Or any other way to do it? Using sas 9.2. It you cannot open the attached. Here is how it looks like: 45 32 28 25 20 18 ....................... atrisk trt1 40 31 26 22 19 16 ....................... atrisk trt2 __________________________________ x axis 1 2 3 4 5 6 time (months) Thanks, Anna

13 REPLIES 13
Reeza
Super User
  1. Can you identify which template you're using, the link is generic to all the template samples.
  2. Please format your data/code sample so it's clear
  3. Post your code - you probably had to modify the code to match your data so making sure it's correct. If possible, include some sample data to replicate the issue. 
  4. It is possible to change the values using the xaxisopts tickvaluelist - making sure to change it everywhere it needs to be changed. 

I have an annotated example below, but it's the survival curve:

https://gist.github.com/statgeek/4f8ccc4ee603b41371e5

 

 

 

Anna_h
Calcite | Level 5
Here is the link and code. The x-axis seems only go to 15 (months) when I try to show 20 months. No know whether it is possible to extend the x-axis or change to years. Anna 'http://support.sas.com/documentation/onlinedoc/stat/ex_code/121/templft2.html' PROC LIFETEST Template (Revised for SAS Global Forum 2013) /****************************************************************/ /* S A S S A M P L E L I B R A R Y */ /* */ /* NAME: TEMPLFT2 */ /* TITLE: PROC LIFETEST Template */ /* (Revised for SAS Global Forum 2013) */ /* PRODUCT: STAT */ /* SYSTEM: ALL */ /* KEYS: graphics, ods, survival analysis, Kaplan-Meier */ /* PROCS: */ /* DATA&colon; */ /* */ /* SUPPORT: saswfk UPDATE: February 5, 2013 */ /* REF: ods graphics */ /* MISC: */ /* NOTES: This sample provides templates for the PROC */ /* LIFETEST survival plot that are more modular and */ /* easier to modify than the default templates. */ /****************************************************************/ %macro SurvivalTemplateRestore; %global TitleText0 TitleText1 TitleText2 yOptions xOptions tips tipl groups bandopts gridopts blockopts censored censorstr; %let TitleText0 = METHOD " Survival Estimate"; %let TitleText1 = &titletext0 " for " STRATUMID; %let TitleText2 = &titletext0 "s"; /* plural: Survival Estimates */ %let yOptions = label="Survival Probability" shortlabel="Survival" linearopts=(viewmin=0 viewmax=1 tickvaluelist=(0 .2 .4 .6 .8 1.0)); %let xOptions = shortlabel=XNAME offsetmin=.05 linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS tickvaluefitpolicy=XTICKVALFITPOL); %let tips = rolename=(_tip1= ATRISK _tip2=EVENT) tiplabel=(_tip1="Number at Risk" _tip2="Observed Events") tip=(x y _tip1 _tip2); %let tipl = tiplabel=(y="Survival Probability"); %let groups = group=STRATUM index=STRATUMNUM; %let bandopts = &groups modelname="Survival"; %let gridopts = autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM) border=true BackgroundColor=GraphWalls:Color Opaque=true; %let blockopts = repeatedvalues=true display=(label values) valuehalign=start valuefitpolicy=truncate labelposition=left labelattrs=GRAPHVALUETEXT valueattrs=GRAPHDATATEXT(size=7pt) includemissingclass=false; %let censored = markerattrs=(symbol=plus); %let censorstr = "+ Censored"; %macro SurvivalTemplate; %local outside _tmpnum; proc template; %do outside = 0 %to 1; define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival%scan(2,2-&outside); dynamic NStrata xName plotAtRisk %if %nrbquote(&censored) ne %then plotCensored; plotCL plotHW plotEP labelCL labelHW labelEP maxTime xtickVals xtickValFitPol rowWeights method StratumID classAtRisk plotBand plotTest GroupName yMin Transparency SecondTitle TestName pValue _byline_ _bytitle_ _byfootnote_; BeginGraph; if (NSTRATA=1) if (EXISTS(STRATUMID)) entrytitle &titletext1; else entrytitle &titletext0; endif; %if not &outside %then if (PLOTATRISK); entrytitle "With Number of Subjects at Risk" / textattrs=GRAPHVALUETEXT; %if not &outside %then %do; endif; %end; %AtRiskLatticeStart layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions); %singlestratum endlayout; %AtRiskLatticeEnd else entrytitle &titletext2; if (EXISTS(SECONDTITLE)) entrytitle SECONDTITLE / textattrs=GRAPHVALUETEXT; endif; %AtRiskLatticeStart layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions); %multiplestrata endlayout; %AtRiskLatticeEnd(%str(class=CLASSATRISK)) endif; if (_BYTITLE_) entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT; else if (_BYFOOTNOTE_) entryfootnote halign=left _BYLINE_; endif; endif; EndGraph; end; %end; run; %mend; %macro entry_p; if (PVALUE < .0001) entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4)); else entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4)); endif; %mend; %macro SingleStratum; 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" &tips legendlabel="Survival"; if (PLOTCENSORED=1) scatterplot y=CENSORED x=TIME / &censored &tipl 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 not &outside %then %do; if (PLOTATRISK=1) innermargin / align=bottom; blockplot x=TATRISK block=ATRISK / &blockopts; endinnermargin; endif; %end; %mend; %macro MultipleStrata; if (PLOTHW) bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / &bandopts datatransparency=Transparency; endif; if (PLOTEP) bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / &bandopts datatransparency=Transparency; endif; if (PLOTCL) if (PLOTBAND) bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts display=(outline); else bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts datatransparency=Transparency; endif; endif; stepplot y=SURVIVAL x=TIME / &groups name="Survival" &tips; if (PLOTCENSORED) scatterplot y=CENSORED x=TIME / &groups &tipl &censored; endif; %if not &outside %then %do; if (PLOTATRISK=1) innermargin / align=bottom; blockplot x=TATRISK block=ATRISK / class=CLASSATRISK &blockopts; endinnermargin; endif; %end; DiscreteLegend "Survival" / title=GROUPNAME location=outside; if (PLOTCENSORED) if (PLOTTEST) layout gridded / rows=2 &gridopts; entry &censorstr; %entry_p endlayout; else layout gridded / rows=1 &gridopts; entry &censorstr; endlayout; endif; else if (PLOTTEST) layout gridded / rows=1 &gridopts; %entry_p endlayout; endif; endif; %mend; %macro AtRiskLatticeStart; %if &outside %then %do; layout lattice / rows=2 rowweights=ROWWEIGHTS columndatarange=union rowgutter=10; cell; %end; %mend; %macro AtRiskLatticeEnd(class); %if &outside %then %do; endcell; cell; layout overlay / walldisplay=none xaxisopts=(display=none); blockplot x=TATRISK block=ATRISK / &class &blockopts; endlayout; endcell; endlayout; %end; %mend; %SurvivalTemplate %mend;
Reeza
Super User

Can you format that please? There's no way I can read that...

Anna_h
Calcite | Level 5
Sorry I cannot format it well. If you copy the link below and paste it to search. That would be the original code from SAS. The issue is that x-axis can only show up to 15 months regardless of how you set the xoptions: (tickvaluelist=(0 1 2.............15) ), Atrisk values can also go upto 15 months. No show after 15 months event I do tickvaluelist=(0 1 2.............15 16 17) or tickvaluelist=(0 2 4 ......30 32...). Just wonder where is the option to extend beyond 15 months. http://support.sas.com/documentation/onlinedoc/stat/ex_code/121/templft2.html Thanks, Anna
Reeza
Super User

So you modified the macro variable below and set the tickvaluelist to a fixed value 0-20 and it still only showed up to 15?

 

 

   %let xOptions   = shortlabel=XNAME offsetmin=.05
                     linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS
                                 tickvaluefitpolicy=XTICKVALFITPOL);

 

 

Jay54
Meteorite | Level 14

The Survival Plot template in PROC Lifetest can get quite complex.  However, often it is easier to create the basic graph if you can extract the data from proc lifetest using ODS Output. See this article which does exactly that, and then displays the Survival plot with a relatively simple SAS 9.2 template.

 

Anna_h
Calcite | Level 5
Sounds like a solution. Will try this. Thanks, Anna
Jay54
Meteorite | Level 14

Separately, If you can attach or send by private message the full runnable program with some data, it will be easier to help.  

Anna_h
Calcite | Level 5
It was a setting in proc lifetest "maxtime=15" need to be updated ..... Thank you for your time! Anna
Reeza
Super User

I tested it out, ran the template and then the sample from the documentation. 

I could not replicate your issue. 

 

Please post your proc lifetest code, if @Jay54 solution doesn't work for you. 

Anna_h
Calcite | Level 5
You are right. This was the problem in proc lifetest: "maxtime=15" should be revised. Problem solved. Thanks for your time! Anna plots=survival(cb=hw atrisk=&g_tick_major1) intervals=&g_tick_major1 alphaqt=0.05 maxtime=15;
Reeza
Super User

Look at xoptions macro value. Set the tickvaluelist values manually to what you want. 

Anna_h
Calcite | Level 5
This template works perfect with 15 months. It does not show beyond 15 month regarding of what you do on tickvaluelist values.

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
  • 13 replies
  • 4345 views
  • 0 likes
  • 3 in conversation