BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MINX
Obsidian | Level 7

 

Does anyone have a good idea to use SGPLOT to generate a serial of graphs (two graphs per page) and re-order the display sequence? For example, graph 1 and 5 for the 1st page, 2 and 6 for 2nd page, etc. I always have to make a macro loop to do that for SGPLOT. It used to be done by PLOT + GREPLAY.  I hope there is any simple solution. Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You can use ODS DOCUMENT to do that. The example below replays everything in the reverse order in which it was created, but you can get the proc to replay any of the pieces in any order you want. Use the LIST command in the proc to get the paths to replay.

 

Hope this helps!

Dan

 

 

ods _all_ close;
ods document name=scat;
proc sort data=sashelp.class out=class; by sex; run;
proc sgplot data=class;
by sex;
scatter x=weight y=height;
run;
ods _all_ close;

ods html;
proc document name=scat;
replay SGPlot#1\BYGroup2#1\SGPlot#1;
replay SGPlot#1\BYGroup1#1\SGPlot#1;
run;
quit;

View solution in original post

8 REPLIES 8
DanH_sas
SAS Super FREQ

The BY statement works with SGPLOT as is does with GPLOT. What issues have you found with it?

MINX
Obsidian | Level 7

Thank you for your quick response. I update my post to clarify my question. Basically it there any simple way as GREPLAY to re-order the display in SGPLOT?

Thank you

DanH_sas
SAS Super FREQ

You can use ODS DOCUMENT to do that. The example below replays everything in the reverse order in which it was created, but you can get the proc to replay any of the pieces in any order you want. Use the LIST command in the proc to get the paths to replay.

 

Hope this helps!

Dan

 

 

ods _all_ close;
ods document name=scat;
proc sort data=sashelp.class out=class; by sex; run;
proc sgplot data=class;
by sex;
scatter x=weight y=height;
run;
ods _all_ close;

ods html;
proc document name=scat;
replay SGPlot#1\BYGroup2#1\SGPlot#1;
replay SGPlot#1\BYGroup1#1\SGPlot#1;
run;
quit;
MINX
Obsidian | Level 7

Thank you. combination of ODS document and proc document work.

ballardw
Super User
proc sort data=sashelp.class out=classsort;
  by sex;
run;

proc sgplot data=classsort;
   by sex;
   scatter x=height y=weight;
run;

Should create one graph per page in ODS destinations such as ODS RTF, PDF or one per worksheet in Excel or tagsets.excelxp.

 

Rick_SAS
SAS Super FREQ

For a general overview of using PROC DOCUMENT to reorder the output, see "Reorder the output from a BY-group analysis in SAS," which contains many links for further reading.

Doug____
Pyrite | Level 9

Can this method also work for generating multiple plots per page (say in a 2x2 layout)?

Rick_SAS
SAS Super FREQ

For most applications, if you want a panel that shows multiple graphs, you can use PROC SGPANEL. There are examples in the doc. For a 2-D lattice example, see this blog post, which shows how to use the PANELBY statement:

proc sgpanel data=Have;
   panelby ID /  rows=2 columns=2 onepanel;
   /* graph statements go here */
run;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2123 views
  • 3 likes
  • 5 in conversation