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
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;
The BY statement works with SGPLOT as is does with GPLOT. What issues have you found with it?
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
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;
Thank you. combination of ODS document and proc document work.
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.
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.
Can this method also work for generating multiple plots per page (say in a 2x2 layout)?
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.