BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DGrint
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Ammonite | Level 13

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_, '&lt;' , '<');
   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;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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)

DGrint
Obsidian | Level 7

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?

 

test.png

WarrenKuhfeld
Ammonite | Level 13

You have to use SG Annotation (or a draw statement).  I have examples at work.  I can dig them out later this morning.

WarrenKuhfeld
Ammonite | Level 13

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_, '&amp;', '&');
   _infile_ = tranwrd(_infile_, '&lt;' , '<');
   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;
Jay54
Meteorite | Level 14

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: 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
  • 5 replies
  • 3119 views
  • 2 likes
  • 4 in conversation