简体   繁体   中英

SAS, plot title

How can I make the title to be "var1=e and var=b", suppose it is a repeat procedure (cannot hardcode).

  data test1;
    input y x var1$ var2$ key$;
    datalines;
    1  2 e b eb
    2  4 e b eb
    3  6 e b eb
    4  1 e b eb
    5  2 e b eb
    6  3 e b eb
    ;
    run;

proc sgplot data=test1 ;
series x=x y=y ;
title "I cannot make the title dynamic";
run;

The special title tokens #BYVAR<n> and #BYVAL<n> get replaced by the n-th by variable name and it's current grouping value. This replacement occurs automatically as part of by group processing in procedures that produce output.

This example demonstrates how to turn off default by-lines and use the special tokens to produce the desired narrative in the output titles.

data cars;
  Wheels = 4;
  set sashelp.cars;
run;

options nobyline;
title "#byvar1=#byval1 and #byvar2=#byval2";

proc sgplot data=cars;
  by wheels make;
  vbar model / response=horsepower nostatlabel;
run;

options byline;
title;

Read the values of VAR1 and VAR2 into a macro and then use that macro in the title.

proc sql noprint;
select var1, var2
   into :var1 trimmed, :var2 trimmed
   from test1(obs=1);
quit;

proc sgplot data=test1 ;
series x=x y=y ;
title "VAR1=&var1 and VAR2=&var2";
run;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM