Search code examples
sasdrawtext

Trying to convert the tick value of Y-Axis Scale in SAS


I'm trying to convert the tick value of Y-Axis Scale from (0 .2 .4 .6 .8 1.0) to (0 .01 .02 .03 .04 .05), but failed. However, no such problem when converting viewmax

PROC TEMPLATE;
DELETE Stat.Lifetest.Graphics.ProductLimitFailure2;
SOURCE Stat.Lifetest.Graphics.ProductLimitFailure2 / FILE='C:\Users\Username\Documents\My SAS Files\9.4\tpl.tpl';
QUIT;

DATA _null_;
INFILE 'C:\Users\Username\Documents\My SAS Files\9.4\tpl.tpl' END=eof;
INPUT;
IF _n_ eq 1 THEN CALL execute('PROC TEMPLATE;'); 
   _infile_ = tranwrd(_infile_, 'viewmax=1', 'viewmax=0.05');     /* tranwrd(var, from, to);*/
   _infile_ = tranwrd(_infile_, 'tickvaluelist=(0 .2 .4 .6 .8 1.0)', 'tickvaluelist=(0 .01 .02 .03 .04 .05)');
   CALL execute(_infile_);
IF eof THEN CALL execute('quit;');
RUN;

PROC LIFETEST DATA=for_analysis_1 PLOT=SURVIVAL (FAILURE TEST ATRISK(OUTSIDE(0.10) MAXLEN=26) NOCENSOR) NOTABLE;
TIME Days * Status(0);
STRATA group;

RUN;

**This code was adapted from: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_kaplan_sect012.htm

Thank you, Joe

I was running SAS with zt mode. It worked successfully after changing to EN mode. Besides, open the .tpl file and edit it by hand is a easy way too! Very appreciate that.

**Change the default SAS® session encoding: https://support.sas.com/kb/51/586.html


Solution

  • It works fine for me.

    PROC TEMPLATE;
    DELETE Stat.Lifetest.Graphics.ProductLimitFailure2;
    SOURCE Stat.Lifetest.Graphics.ProductLimitFailure2 / FILE='....dir....\tpl.tpl';
    QUIT;
    
    DATA _null_;
    INFILE '....dir....\tpl.tpl' END=eof;
    INPUT;
    IF _n_ eq 1 THEN CALL execute('PROC TEMPLATE;'); 
       _infile_ = tranwrd(_infile_, 'viewmax=1', 'viewmax=0.05');     /* tranwrd(var, from, to);*/
       _infile_ = tranwrd(_infile_, 'tickvaluelist=(0 .2 .4 .6 .8 1.0)', 'tickvaluelist=(0 .01 .02 .03 .04 .05)');
       CALL execute(_infile_);
    IF eof THEN CALL execute('quit;');
    RUN;
    
    proc lifetest data=sashelp.BMT
       plots=survival(cb=hw failure test atrisk(outside maxlen=13));
       time T * Status(0);
       strata Group;
    run;
    

    What you can do to test is, first, run this exact code (using the built in dataset); if that works, then you know it's an issue with your data. Second, I wonder if you might have some issue with character encoding (I'm running in EN-US mode, are you in UTF-8? Are the spaces real spaces, or maybe 'A0'x web spaces?). TRANWRD is quite the "hammer" to use here. Maybe consider using a different way to change the values that's easier to debug. At least, step through it with some PUT statements to see if the TRANWRD is actually doing anything (before/after that line, PUT the infile value IF "tickvaluelist" is found).

    Also consider it's possible that the tickvaluelist is separated across lines. Open the .tpl file and just see what you have! There's nothing saying you need to do it this way - you could just write the PROC TEMPLATE code directly. What I'd probably do is run that first PROC TEMPLATE that sources it to a file, then edit it by hand, then run it as part of your code. The only reason not to do that is if you want to programatically change the tick values list based on what's in the data, but even that you could do differently - like with a macro variable.

    Below is what works for me and an image.

    PROC LIFETEST output with 0.00-0.05 Y axis