BookmarkSubscribeRSS Feed
kz_
Quartz | Level 8 kz_
Quartz | Level 8

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). 

 

 

3 REPLIES 3
Ksharp
Super User

I remember @Rick_SAS  answer this question before by PROC DOCUMENTATION .

Rick_SAS
SAS Super FREQ

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."

GraphGuy
Meteorite | Level 14

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 480 views
  • 6 likes
  • 4 in conversation