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

How does one change the font size in legend in KM plot in ods output.

 

Creating a new style definition using the TEMPLATE procedure, but even when I customized the style, it did not seem to help.

here is my code,

 



/*km curves*/
proc template;
      define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival ;

         dynamic NStrata xName plotAtRisk  plotCL plotHW plotEP
            labelCL labelHW labelEP maxTime StratumID classAtRisk plotBand
            plotTest GroupName yMin Transparency SecondTitle TestName pValue;

         BeginGraph / datacontrastcolors=(Black LTGRAY) datalinepatterns=(1)  border=false  
              ;
            layout lattice / rows=2 columns=1 columndatarange=unionall border=false
                             rowweights=(.85 .15);

               layout overlay / border=false
                  xaxisopts=(shortlabel=XNAME offsetmin=.05 labelattrs=(size=12pt weight=bold) tickvalueattrs=(  FAMILY="Helvetica" size=12pt weight=bold)
                  linearopts=(viewmax=MAXTIME tickvaluelist=(0 50 100 150 200 250 ) ))
                  yaxisopts=(label=
                            "survival" shortlabel="Survival" labelattrs=(size=16pt weight=bold) tickvalueattrs=(size=12pt weight=bold)
                    linearopts=(viewmin=0 viewmax=1  tickvaluelist=(0 .2 .4 .6 .8 1.0))) ;

                  stepplot y=SURVIVAL x=TIME / group=STRATUM index=STRATUMNUM
                     name="Survival" rolename=(_tip1=ATRISK _tip2=EVENT) tip=(y
                     x Time _tip1 _tip2) LINEATTRS=(THICKNESS=5 PATTERN=1 )  ;
            DiscreteLegend "Survival" / location=inside autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM) across=1 border=false ;
               endlayout;
              endlayout;
         EndGraph;
      end;
   run;


proc template;
define style styles.mystyle;
parent=STYLES.DEFAULT;

style GraphAxisLines from GraphAxisLines /
      linethickness = 3px  ;
      
style GraphAxisLines from GraphAxisLines /
      ContrastColor =Black  ;
style graphfonts from graphfonts /      
                 'GraphLabelFont' = ("<sans-serif>, <MTsans-serif>",16pt,bold);

 class GraphFonts / 'GraphLabelFont'=("Helvetica", 18pt, bold)
                          'GraphValueFont'=("Helvetica", 15pt, bold)
                          'GraphTitleFont'=("Helvetica", 25pt, bold);
end;
run;

I was able to change the font to bold but not the size and the family for font.  .

 

Thank you,

 

Jade

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Rhodochrosite | Level 12

 

If it were me, I would use the approach outlined in the Kaplan-Meir chapter in SAS/STAT.

Here for example is the chapter for 14.1 and 14.2

https://support.sas.com/documentation/onlinedoc/stat/141/kaplan.pdf

https://support.sas.com/documentation/onlinedoc/stat/142/kaplan.pdf
There are older versions for older releases.  The DATA step and %include are a one-time set up that gives you access to the macros and macro variables.  This one gets the macros for 14.2.  The chapter for your release shows you how to get them for other releases.  Just run it as is.  Then provide the macro variables.  Change any that you want to change.  Compile them all.  Then run the proc.  The Kaplan-Meier chapter has lots of examples.  There are many customizations that you can easily peform this way.

data _null_;
   %let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/142;
   infile "http:&url/templft.html" device=url;

   file 'macros.tmp';
   retain pre 0;
   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

%let LegendOpts = title=GROUPNAME location=outside
     valueattrs=(family="helvetica" size=15pt weight=bold)
     titleattrs=(family="helvetica" size=25pt weight=bold);

%CompileSurvivalTemplates

ods graphics on;
proc lifetest data=sashelp.BMT plots=survival(cb=hw test); 
   ods select survivalplot;
   time T * Status(0);
   strata Group;
run;

 

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Rhodochrosite | Level 12

 

If it were me, I would use the approach outlined in the Kaplan-Meir chapter in SAS/STAT.

Here for example is the chapter for 14.1 and 14.2

https://support.sas.com/documentation/onlinedoc/stat/141/kaplan.pdf

https://support.sas.com/documentation/onlinedoc/stat/142/kaplan.pdf
There are older versions for older releases.  The DATA step and %include are a one-time set up that gives you access to the macros and macro variables.  This one gets the macros for 14.2.  The chapter for your release shows you how to get them for other releases.  Just run it as is.  Then provide the macro variables.  Change any that you want to change.  Compile them all.  Then run the proc.  The Kaplan-Meier chapter has lots of examples.  There are many customizations that you can easily peform this way.

data _null_;
   %let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/142;
   infile "http:&url/templft.html" device=url;

   file 'macros.tmp';
   retain pre 0;
   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

%let LegendOpts = title=GROUPNAME location=outside
     valueattrs=(family="helvetica" size=15pt weight=bold)
     titleattrs=(family="helvetica" size=25pt weight=bold);

%CompileSurvivalTemplates

ods graphics on;
proc lifetest data=sashelp.BMT plots=survival(cb=hw test); 
   ods select survivalplot;
   time T * Status(0);
   strata Group;
run;

 

jadet
Calcite | Level 5
Thank you, WarrenKuhfeld,



This seems more intuitive for changing the font size of legend in KM plot, but I have SAS/Stat 13.2 here, do you have codes to access the macros and macro variables for 13.2.



Jade
WarrenKuhfeld
Rhodochrosite | Level 12

 

 

Just change 142 in the URL to 132 and 142 in the code that fetches the macros to 132.

*
documentation:
https://support.sas.com/documentation/onlinedoc/stat/132/kaplan.pdf
;

data _null_;
   %let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/132;
   infile "http:&url/templft.html" device=url;

   file 'macros.tmp';
   retain pre 0;
   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

%let LegendOpts = title=GROUPNAME location=outside
     valueattrs=(family="helvetica" size=15pt weight=bold)
     titleattrs=(family="helvetica" size=25pt weight=bold);

%CompileSurvivalTemplates

ods html body='b.html';
ods graphics on;
proc lifetest data=sashelp.BMT plots=survival(cb=hw test); 
   ods select survivalplot;
   time T * Status(0);
   strata Group;
run;
ods html close;

 

jadet
Calcite | Level 5
thank you very much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3579 views
  • 2 likes
  • 2 in conversation