Search code examples
sastitle

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;

Solution

  • 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;