I have created three different graphs with proc sgplot that each use the same by-group: a series plot, a histogram, and a heat map.
Is it possible to have the output put the series plot, histogram and heat map for group 1 on page 1, then the series plot, histogram and heat map for group 2 on page 2, etc?
Currently I only know how to plot all of the series plots, then all of the histograms, and so on, when using by groups (rather than typing out a plot statement for each group individually).
I remember @Rick_SAS answer this question before by PROC DOCUMENTATION .
KSharp is correct: You can use PROC DOCUMENT to replay the graphs in a different order, as shown in the article "Reorder the output from a BY-group analysis in SAS."
One way to accomplish what you're wanting is to loop through the values and call a macro, rather than using the built-in 'by' statement. Here is a minimal example demonstrating how to do it that way:
data my_data; set sashelp.electric;
run;
%macro do_graphs(cust);
data tempdata; set my_data (where=(customer="&cust"));
run;
title "&cust";
proc sgplot data=tempdata;
series x=year y=revenue;
run;
proc sgplot data=tempdata;
histogram revenue;
run;
proc sgplot data=tempdata;
heatmap x=year y=revenue;
run;
%mend;
proc sql; create table loopdata as select unique customer from my_data; quit; run;
data _null_; set loopdata;
call execute('%do_graphs('|| customer ||');');
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.