I'm using SGPLOT to create a KM plot and the xaxistable statement to add a number a risk table under the graph. When I give the xaxistable a title it is positioned above the second column in the table, not above the first column containing the row names. How can I get the title to appear above the first column?
Thanks
xaxistable atrisk1 / x=risk_time1 location=outside position=bottom class=e04brand
title="N at Risk"
titleattrs=GraphUnicodeText nomissingclass;
Here is an example of using PROC LIFETEST using techniques fromhttp://support.sas.com/documentation/onlinedoc/stat/142/kaplan.pdf . I also show an SG annotation example, but outside the context of a KM plot.
data _null_;
%let url = //support.sas.com/documentation/onlinedoc/stat;
infile "http:&url/ex_code/143/templft.html" device=url;
file 'macros.tmp';
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
%macro StmtsBeginGraph;
* Coordinates are ad hoc, and there are many
available coordinate systems.
See the documentation for more information.;
drawtext textattrs=(weight=Bold) 'CD4<100 cells/(*ESC*){unicode mu}L' /
x=8 y=14 width=20;
%mend;
%CompileSurvivalTemplates
ods html body='b.html';
ods graphics on;
proc lifetest data=sashelp.BMT
plots=survival(atrisk outside maxlen=13);
time T * Status(0);
strata Group;
run;
data anno;
label = 'CD4<100 cells/(*ESC*){unicode mu}L';
function = 'text';
drawspace = 'GraphPercent';
x1 = 15;
y1 = 5;
width = 25;
run;
proc sgplot data=sashelp.class sganno=anno;
scatter y=weight x=height;
run;
ods html close;
I have nothing to test this on, but I am guessing something in:
GraphUnicodeText
Is telling the title to center justify the title. Check in the style you are using or put the style elements in yourself with:
titleattrs=(just=l)
Perhaps I wasn't clear, the title is left aligned but it is above the data values rather than above the data labels. How can I position it above the data labels?
You have to use SG Annotation (or a draw statement). I have examples at work. I can dig them out later this morning.
Here is an example of using PROC LIFETEST using techniques fromhttp://support.sas.com/documentation/onlinedoc/stat/142/kaplan.pdf . I also show an SG annotation example, but outside the context of a KM plot.
data _null_;
%let url = //support.sas.com/documentation/onlinedoc/stat;
infile "http:&url/ex_code/143/templft.html" device=url;
file 'macros.tmp';
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
%macro StmtsBeginGraph;
* Coordinates are ad hoc, and there are many
available coordinate systems.
See the documentation for more information.;
drawtext textattrs=(weight=Bold) 'CD4<100 cells/(*ESC*){unicode mu}L' /
x=8 y=14 width=20;
%mend;
%CompileSurvivalTemplates
ods html body='b.html';
ods graphics on;
proc lifetest data=sashelp.BMT
plots=survival(atrisk outside maxlen=13);
time T * Status(0);
strata Group;
run;
data anno;
label = 'CD4<100 cells/(*ESC*){unicode mu}L';
function = 'text';
drawspace = 'GraphPercent';
x1 = 15;
y1 = 5;
width = 25;
run;
proc sgplot data=sashelp.class sganno=anno;
scatter y=weight x=height;
run;
ods html close;
I am thinking one way to do this (without annotation) would be to add another class level, with the title you want, and provide missing values. If you want the bold text, you could possibly use the TEXTGROUP. This will line up this "title" right aligned with the other group values. I have not tried it yet myself...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.