I use Proc Lifetest to create KM curves by using SAS macro but I cannot find a easy way to make x-axis and y-axis meet at (0,0) to the bottom left corner using lifetest and sas macro. I would not use sgplot to make it. Many thanks.
Figure found online
https://support.sas.com/documentation/onlinedoc/stat/151/kaplan.pdf
Search for
%let yoptions=
and
%let xoptions=.
You will see several examples and general info.
Next, look at page 899.
Now try to modify the example to specify offsetmin= instead of the options in that example.
Thank you for your reply.
I added offsetmin=0 to xOptions and yOptions. Then y-axis starts from 0 a the bottom left corner but x-axis still does Not start from 0 (shown below).
Hi @SeaMoon_168,
The following code, copied right out of the guide linked by @WarrenKuhfeld, works for me in SAS Enterprise Guide 7.15 HF8 (7.100.5.6214) (32-bit). If it still isn't working for you, you might need to provide more details.
ods graphics on;
data _null_;
%let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/151;
infile "http:&url/templft.html" device=url;
file 'macros.tmp';
retain pre 0;
input;
_infile_ = tranwrd(_infile_, '&', '&');
_infile_ = tranwrd(_infile_, '<' , '<');
if index(_infile_, '</pre>') then pre = 0;
if pre then put _infile_;
if index(_infile_, '<pre>') then pre = 1;
run;
%inc 'macros.tmp' / nosource;
%ProvideSurvivalMacros
%let yOptions = offsetmin=0;
%let xOptions = offsetmin=0;
%CompileSurvivalTemplates
proc lifetest data=sashelp.BMT plots=survival(cb=hw test) notable;
time T * Status(0);
strata Group;
run;
That code produces the following output.
Thank you for your reply. Shall I just copy and use the same code between "ods graphics on;" and "%CompileSurvivalTemplates" without any changes? But it does not work ...
Here is my code with adding your code at the beginning. Thanks.
ods graphics on;
data _null_;
%let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/151;
infile "http:&url/templft.html" device=url;
file 'macros.tmp';
retain pre 0;
input;
_infile_ = tranwrd(_infile_, '&', '&');
_infile_ = tranwrd(_infile_, '<' , '<');
if index(_infile_, '</pre>') then pre = 0;
if pre then put _infile_;
if index(_infile_, '<pre>') then pre = 1;
run;
%inc 'macros.tmp' / nosource;
%inc "D:\XXX\KMmacros.sas";
%ProvideSurvivalMacros
%let LegendOpts = ;
%let tatters = textattrs=(size=12pt family='Times New Roman');
%let TitleText0 = "XXX";
%let TitleText1 = &titletext0 " for " STRATUMID/&tatters;
%let TitleText2 = &titletext0/&tatters;
%let ntitles=1;
%let yOptions = offsetmin=0
label="XXX"
labelattrs=(size=12pt family='Times New Roman')
tickvalueattrs=(size=12pt family='Times New Roman')
linearopts=(viewmin=0 viewmax=1
tickvaluelist=(0 .2 .4 .6 .8 1));
%let xOptions = offsetmin=0
shortlabel=XNAME
labelattrs=(size=12pt family='Times New Roman')
tickvalueattrs=(size=12pt family='Times New Roman')
linearopts=(viewmin=0 viewmax=2
tickvaluelist=(0 .5 1 1.5 2));
%let AtRiskOpts = labelattrs=(family='Times New Roman' size=12pt)
valueattrs=(family='Times New Roman' size=12pt);
%CompileSurvivalTemplates
Apologies for not responding. I ran your code with the following proc lifetest at the end, and the axes still came out as desired. Did you ever figure out the issue?
data toplot; set sashelp.BMT; T = T / 200; run; proc lifetest data=toplot plots=survival(cb=hw test) notable; time T * Status(0); strata Group; run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.