Data visualization with SAS programming

Multiple graphs on one page in Enterprise Guide?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Multiple graphs on one page in Enterprise Guide?

[ Edited ]

I'm generating four graphs using enterprise guide. I'd like to place them on a page 2 across, two down.

In regular SAS, you would do something like:

 

ods pdf file='file.pdf' startpage=no;
ods layout start width=8in height=10.5in; /*identify width and height of entire page leaving room for margins*/
ods region x=0in width=2.25in y=0in height=5in; /*identify region boundaries*/
{code with output}
ods region x=2.5in width=2.25in y=0in height=5in; /*identify region boundaries*/
{code with output}
ods region x=5in width=2.25in y=0in height=5in; /*identify region boundaries*/
{code with output}
ods region x=0in width=8in y=5.25in height=5in; /*identify region boundaries*/
{code with output}
ods layout end;


However, how do I get the code in blue to run at the beginning of the process flow,
the code in red to run at the end so that all the graphs will be in the same PDF?

 


Accepted Solutions
Solution
‎10-13-2015 01:57 PM
SAS Super FREQ
Posts: 1,171

Re: Multiple graphs on one page in Enterprise Guide?

Posted in reply to SciFiGuy0

If one procedure is the restriction, this GTL graph should work.

 

/*--Four Graph Template--*/
proc template;
define statgraph four_graphs;
begingraph;
layout lattice / columns=2 rowgutter=10 columngutter=10;
layout overlay / border=true;
barchart category=sex response = height / group=sex stat=mean name='a';
discretelegend 'a';
endlayout;
layout overlay / border=true;
barchart category= sex response = height / group=sex stat=mean name='b';
discretelegend 'b';
endlayout;
layout overlay / border=true;
barchart category=sex response = height / group=age groupdisplay=cluster stat=mean name='c';
discretelegend 'c';
endlayout;
layout overlay / border=true;
barchart category=sex response=weight / group=age groupdisplay=cluster stat=mean name='d';
discretelegend 'd';
endlayout;
endlayout;
endgraph;
end;
run;

ods _all_ close;
ods pdf file='C:\four_grafs_gtl.pdf';
ods graphics / reset width=8in height=6in imagename='four_graphs';
proc sgrender data=sashelp.class template=four_graphs;
run;
ods pdf close;

View solution in original post


All Replies
Regular Contributor
Posts: 212

Re: Multiple graphs on one page in Enterprise Guide?

Posted in reply to SciFiGuy0
Occasional Contributor
Posts: 18

Re: Multiple graphs on one page in Enterprise Guide?

[ Edited ]
Posted in reply to DartibaliRodrigo

Thanks!  That's a great way to do it using SAS directly.   However, I think it's a little more difficult in EG.  I'm not sure how to control the ODS statements so they set-up only in the beginning and don't close out between graphs.

 

It seems like whatever I do, EG generates an ODS Close All statement after procs.   That stops me from putting multiple graphs on one page  Smiley Sad

SAS Super FREQ
Posts: 8,862

Re: Multiple graphs on one page in Enterprise Guide?

Posted in reply to SciFiGuy0
you can start your program with
ODS _ALL_ CLOSE;
to close the default EG destination that's open. Your posted code shows the end for ODS LAYOUT, but not ODS PDF CLOSE; (which I assume was a typo) If you close all the automatic EG destinations and enclose your code in the correct ODS "sandwich", then even EG should put the output from all 4 procedures into 1 pdf file.

For example, without any attempt to replicate what you are doing with ODS LAYOUT, the output from all 4 procedures goes into 1 PDF file when I run this code.

Cynthia

ods _all_ close;
ods pdf file='c:\temp\four_grafs.pdf';
title;
proc sgplot data=sashelp.class;
vbar sex / response = height group=sex stat=mean;
run;

proc sgplot data=sashelp.class;
vbar sex / response = weight group=sex stat=mean;
run;

proc sgplot data=sashelp.class;
vbar sex / response = height group=age groupdisplay=cluster stat=mean;
run;

proc sgplot data=sashelp.class;
vbar sex / response = weight group=age groupdisplay=cluster stat=mean;
run;

ods pdf close;
Occasional Contributor
Posts: 18

Re: Multiple graphs on one page in Enterprise Guide?

[ Edited ]
Posted in reply to Cynthia_sas

Thanks for your reply! This brings me closer to the goal of putting all the graphs on one page.  I was hoping to use it in EG as opposed to regular SAS.   The code you provided would work perfectly in SAS  Smiley Happy

Cynthia_sas wrote:
you can start your program with
ODS _ALL_ CLOSE;
to close the default EG destination that's open. Your posted code shows the end for ODS LAYOUT, but not ODS PDF CLOSE; (which I assume was a typo) If you close all the automatic EG destinations and enclose your code in the correct ODS "sandwich", then even EG should put the output from all 4 procedures into 1 pdf file.

For example, without any attempt to replicate what you are doing with ODS LAYOUT, the output from all 4 procedures goes into 1 PDF file when I run this code.

Cynthia
SAS Super FREQ
Posts: 1,171

Re: Multiple graphs on one page in Enterprise Guide?

[ Edited ]
Posted in reply to SciFiGuy0

You can use ODS LAYOUT GRIDDED with 2 columns and render smaller graphs.

 

ods _all_ close;
ods pdf file='C:\four_grafs.pdf';
title;

ods layout gridded columns=2;
ods region;
ods graphics / reset width=3in height=2in;
proc sgplot data=sashelp.class;
vbar sex / response = height group=sex stat=mean;
run;

ods region;
proc sgplot data=sashelp.class;
vbar sex / response = weight group=sex stat=mean;
run;

ods region;
proc sgplot data=sashelp.class;
vbar sex / response = height group=age groupdisplay=cluster stat=mean;
run;

ods region;
proc sgplot data=sashelp.class;
vbar sex / response = weight group=age groupdisplay=cluster stat=mean;
run;

ods layout end;

ods pdf close;

Occasional Contributor
Posts: 18

Re: Multiple graphs on one page in Enterprise Guide?

[ Edited ]
Posted in reply to SciFiGuy0

Unfortunately, EG seems to put an ODS close on each proc, nomatter what options you set.  That basically blocks the multiple graphs thing.  I think this is a bug as you're supposed to be able to turn off the "sandwich" using the options.

 

Your option above would work great in SAS directly.   I suspect I'm going to have to just code it  Smiley Sad

Solution
‎10-13-2015 01:57 PM
SAS Super FREQ
Posts: 1,171

Re: Multiple graphs on one page in Enterprise Guide?

Posted in reply to SciFiGuy0

If one procedure is the restriction, this GTL graph should work.

 

/*--Four Graph Template--*/
proc template;
define statgraph four_graphs;
begingraph;
layout lattice / columns=2 rowgutter=10 columngutter=10;
layout overlay / border=true;
barchart category=sex response = height / group=sex stat=mean name='a';
discretelegend 'a';
endlayout;
layout overlay / border=true;
barchart category= sex response = height / group=sex stat=mean name='b';
discretelegend 'b';
endlayout;
layout overlay / border=true;
barchart category=sex response = height / group=age groupdisplay=cluster stat=mean name='c';
discretelegend 'c';
endlayout;
layout overlay / border=true;
barchart category=sex response=weight / group=age groupdisplay=cluster stat=mean name='d';
discretelegend 'd';
endlayout;
endlayout;
endgraph;
end;
run;

ods _all_ close;
ods pdf file='C:\four_grafs_gtl.pdf';
ods graphics / reset width=8in height=6in imagename='four_graphs';
proc sgrender data=sashelp.class template=four_graphs;
run;
ods pdf close;

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 744 views
  • 0 likes
  • 4 in conversation