BookmarkSubscribeRSS Feed
MeganE
Pyrite | Level 9

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

 

16 REPLIES 16
ballardw
Super User

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.

MeganE
Pyrite | Level 9

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

ballardw
Super User

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.   

 

MeganE
Pyrite | Level 9

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

Reeza
Super User

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?

MeganE
Pyrite | Level 9

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

Reeza
Super User

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');

 

MeganE
Pyrite | Level 9

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

 

 

 

 

 

 

 

Reeza
Super User

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

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

MeganE
Pyrite | Level 9

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

 

 

 

 

 

ballardw
Super User

options() is not for PDF

 

ods pdf startpage='now';

ods pdf startpage='never';

MeganE
Pyrite | Level 9

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

 

 

 

Reeza
Super User

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. 

MeganE
Pyrite | Level 9

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

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 3680 views
  • 2 likes
  • 3 in conversation