Search code examples
group-bysascounterfootnotes

Adding graph count in footnote in SAS


Hi I am trying to use BY GROUP statement in SAS to generate multiple graphs. I want to print each graph to an individual file named after BY GROUP varaible value, plus I want to add a footnote to each graph where I want add text "This graph is 2300-01" to graph 1 and the want to increment it by 1 for next graph to "This graph is 2300-02" and so on.

goptions reset=all border;
data grainldr;
length country $ 3 type $ 5;
input year country $ type $ amount;
megtons=amount/1000;
datalines;
1995 BRZ  Wheat    1516
1995 BRZ  Rice     11236
1995 BRZ  Corn     36276
1995 CHN  Wheat    102207
1995 CHN  Rice     185226
1995 CHN  Corn     112331
1995 INS  Wheat    .
1995 INS  Rice     49860
1995 INS  Corn     8223
1995 USA  Wheat    59494
1995 USA  Rice     7888
1995 USA  Corn     187300
; 

 proc sort data=grainldr out=temp;
 by country;
 run;

 proc sgplot data=temp (where=(megtons gt 31));
 by country;

 series x=type y= amount;
 series x=type y=megtons;
 title "Leading #byval(country) Producers"
    j=c "1995 and 1996";
 footnote1 j=r  "This graph is 2300-&XY."; 
 run;

quit;


Solution

  • If you had a BY variable in your data set you could use it. For example, if you had a variable called CID (country id), and it had values "01", "02" etc, you could then do something like this:

    proc sort data=grainldr out=temp;
      by country cid;
    run;
    
    footnote1 j=r  "This graph is 2300-#byval2"; 
    proc sgplot data=temp (where=(megtons gt 31));
      by country cid;
      ...
      ...
    

    run;

    In this case #BYVAL2 refers to the value of the second BY variable, i.e. CID