Data visualization with SAS programming

Forcing 2 graphs per page with SGPLOT

Reply
Frequent Contributor
Posts: 128

Forcing 2 graphs per page with SGPLOT

[ Edited ]

Hi all,

 

I have SGPLOT code working and it outputs 40+ graphs (this is dependent on the input and can change from run to run) to a pdf.  I'm trying to force 2 graphs on one page as a space saver.  I've tried startpage=no or startpage=never, and any of those end up reducing everything to one page and i only end up with 1 page and 1 graph instead of 40 pages and 40 graphs.

 

 

Here's my code: (EDITED to note that i do not have the abilty to post the actual code as it's on an enclave computer, with no internet access and no copy rights out of it into another machine).

 

sgplot.png

 

Thanks

Megan

 

Super User
Posts: 11,114

Re: Forcing 2 graphs per page with SGPLOT

Look at adjusting your PAGESIZE option for output with the OPTIONS statement and using ODS Graphics options to set the height and width of your graph output.

 

ODS Graphics/ height =4in width=7in;

would set the graph size to 4 by 7 inches.

If your pagesize is at least 8.5in by 8in two should fit. There will be some space between the graphs.

 

When you say that you have created one page with one graph where you expect more then you seem to have something else going one.

 

Also you show a %do loop but no %end statement so you may be having issues with your macro in general that would be very hard to diagnose without data and full code.

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

[ Edited ]

Sorry, there is an actual %end.  I have an if/then based on something else and pulled the other one out to simplify the picture for the post.  I've updated the picture.

 

When i do startpage=no or startpage=never, that's when it goes from 1 graph per page and 40+ pages to just 1 graph and 1 page.  When remove startpage, then it goes back to normal.

 

 I added the ods graphics height and width and it made the graphs smaller, and visually there is plenty of page left for a second graph per page, but there's still only one graph per page.

 

EDITED to add screenshot of graph output.  As you can see, there's PLENTY of room for 2 on each page:

sgplot2.png

Super User
Posts: 11,114

Re: Forcing 2 graphs per page with SGPLOT

Please show the actual code with the ods options.

Did you have a working program without macros that would place two graphs as needed?

From online documentation for ODS PDF

STARTPAGE=NEVER | NO | NOW | YES

controls page breaks.

NEVER

specifies not to insert page breaks, even before graphics procedures.

 

CAUTION:
Each graph normally requires an entire page. The default behavior forces a new page after a graphics procedure. STARTPAGE=NEVER turns off that behavior, so specifying STARTPAGE= NEVER might cause graphics to overprint.   
NO

specifies that no new pages be inserted at the beginning of each procedure, or within certain procedures, even if new pages are requested by the procedure code. A new page will begin only when a page is filled or when you specify STARTPAGE=NOW.

 

CAUTION:
Each graph normally requires an entire page. The default behavior forces a new page after a graphics procedure, even if you use STARTPAGE=NO. STARTPAGE=NEVER turns off that behavior, so specifying STARTPAGE= NEVER might cause graphics to overprint.   

 

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

I did post the code.  What's there is my testing code.  And no, i don't have a version without the macros written.

Super User
Posts: 19,064

Re: Forcing 2 graphs per page with SGPLOT

FYI - Code as a picture and that we can't run isn't very helpful. Ideally you'd use a SASHELP dataset and we could replicate your issue. At minimum I'm not likely to type out your code to test it.

 

Given what you've shown, startpage should work, but I don't see that listed anywhere in the code. 


Can you show the code when you have that option on? And what version of SAS are you using?

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

I can't post the actual code.  SAS is on another computer that is separate from the internet and doesn't allow copy and paste out of it.  So screenshots is the best i can do.

 

SAS 9.4 32bit

Super User
Posts: 19,064

Re: Forcing 2 graphs per page with SGPLOT

I'd probably do something like the following, but this is untested.

 

%if %sysfunc(mod(&i, 2)) = 0 %then %do;
ods pdf options(startpage='now');
%end;
%else ods pdf options(startpage='never');

 

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

I wasn't sure where to put it, but seeing the &i, i put it inside the macro, but SAS didn't like that.

sgplot3.png

 

sgplot3error.png

 

 

 

 

 

 

 

Super User
Posts: 19,064

Re: Forcing 2 graphs per page with SGPLOT

You forgot the ODS (or I did in my test code).

Either way, add the ODS to the ELSE statement and try that.

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

Looks like i did.  For some reason it recognizes the first one but not the second one.  I don't see any different in the ods pdf line, do you??

 

sgplot4.png

 

 

 

 

 

Super User
Posts: 11,114

Re: Forcing 2 graphs per page with SGPLOT

options() is not for PDF

 

ods pdf startpage='now';

ods pdf startpage='never';

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

Same thing.  Recognizes the first line, not the second.  Gotta love the error with 'never' because it's looking for never.  ???

 

I removed the quotes around now and never just in case and then it had a problem with the proc sgplot line.

 

sgplot4.png

 

 

 

Super User
Posts: 19,064

Re: Forcing 2 graphs per page with SGPLOT

Try changing the %else to %else %do; ods PDF ... etc; %end;

 

If you can mock up a simple example on your desktop that we can run, using SASHELP.CARS or Heart then I can test it on my side. Unfortunately I don't have time to do this today. 

Frequent Contributor
Posts: 128

Re: Forcing 2 graphs per page with SGPLOT

Well it works with 4 graphs right in a row, so maybe it has something to do with the do loop in my real code?  Because when i do startpage='never' on my code, it overwrites each one each time and i end up with only 1 page and 1 graph.

 

sgplot4.png

 

Ask a Question
Discussion stats
  • 16 replies
  • 206 views
  • 2 likes
  • 3 in conversation