Data visualization with SAS programming

How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT and GREPLAY

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT and GREPLAY

[ Edited ]

 

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


Accepted Solutions
Solution
‎09-11-2017 01:57 PM
SAS Super FREQ
Posts: 925

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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


All Replies
SAS Super FREQ
Posts: 925

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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

Contributor
Posts: 20

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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

Solution
‎09-11-2017 01:57 PM
SAS Super FREQ
Posts: 925

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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;
Contributor
Posts: 20

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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

Super User
Posts: 11,118

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT

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.

 

SAS Super FREQ
Posts: 3,623

Re: How to generate a serial of graphs by SGPLOT as we use BY statement in PROC GPLOT and GREPLAY

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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