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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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

7 REPLIES 7
SciFiGuy0
Obsidian | Level 7

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  😞

Cynthia_sas
SAS Super FREQ
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;
SciFiGuy0
Obsidian | Level 7

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
Jay54
Meteorite | Level 14

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;

SciFiGuy0
Obsidian | Level 7

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  😞

Jay54
Meteorite | Level 14

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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