Programming the statistical procedures from SAS

proc template: how to change legend font size in KM plot

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

proc template: how to change legend font size in KM plot

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


Accepted Solutions
Solution
‎06-08-2017 03:07 PM
SAS Employee
Posts: 154

Re: proc template: how to change legend font size in KM plot

 

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


All Replies
Solution
‎06-08-2017 03:07 PM
SAS Employee
Posts: 154

Re: proc template: how to change legend font size in KM plot

 

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;

 

New Contributor
Posts: 3

Re: proc template: how to change legend font size in KM plot

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
SAS Employee
Posts: 154

Re: proc template: how to change legend font size in KM plot

 

 

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;

 

New Contributor
Posts: 3

Re: proc template: how to change legend font size in KM plot

thank you very much!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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