BookmarkSubscribeRSS Feed
sassy7
Obsidian | Level 7

Hello experts,

I would like to save the output of a PROC SGPLOT/SGPANEL with a BY statement on multiple pdf pages.

At present there are about 8 different categories - values of the by variable - that I would like to represent with a graph, hence using the BY statement is the easiest thing.

Problem is, the pdf output stops after the first graph, namely the first value of the by variable. 

I browsed a bit on communities.sas.com and saw several papers/answers about multiple graphs in a PDF page (meaning one PDF page) but my case is the opposite.

As PDF output, I would like to obtain multiple PDF pages, generated by proc sgplot/proc sgpanel with a BY statement.

How to save all the graphs in PDF?

Kind regards

8 REPLIES 8
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Have you sorted the input data set by the BY variable? When you use the BY statement in a SAS procedure, it needs to be sorted by that variable. 

sassy7
Obsidian | Level 7
Of course it's sorted 😉
DanH_sas
SAS Super FREQ

Are you using ODS LAYOUT in your code?

sassy7
Obsidian | Level 7
Yes, it's used, but as a PDF only the first page (pdf) is visible
DanH_sas
SAS Super FREQ

Do you have the ADVANCE=BYGROUP option on your ODS LAYOUT GRIDDED statement?

sassy7
Obsidian | Level 7

Hello,

I tried to use "ods layout gridded advance=bygroup;" but it prints only the first page, both as SAS Results and PDF.

Here is my SAS code: with this code it's possible to get the whole output in SAS results, but only the first page as PDF.

the variable KIND contains 8 unique values, hence the graph is grouped by KIND variable.

 

ODS layout start;

proc sgpanel data=work.ds_sas dattrmap=attrmap;
panelby kind/ novarname spacing=5 columns=1 ;
vbar YEAR / response=Percent group=category groupdisplay=stack attrid=myid;
rowaxis grid values=(0 to 100 by 10) label="Percentage";
colaxistable nhouse / class=category stat=sum title="house num.";
label category="Category"
kind="Kind";
run;

ods layout end;

DanH_sas
SAS Super FREQ

Okay, instead of using ODS LAYOUT and ADVANCE=BYGROUP, remove the layout code and use STARTPAGE=BYGROUP on the ODS PDF statement. That should get you what you want.

 

Hope this helps!
Dan

ballardw
Super User

@sassy7 wrote:
Yes, it's used, but as a PDF only the first page (pdf) is visible

Another example of where you really need to provide the entire code as interactions between all the options between procedure and ods destination options need to be known to address such.

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
  • 8 replies
  • 1494 views
  • 0 likes
  • 4 in conversation