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?
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;
I think this will help you.
Multiple Graphs on One page, the easy way (PDF) and the hard way (RTF)
Att
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 😞
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 🙂
@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
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;
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 😞
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: