BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

Hi all. I am trying to print 4 graphs per page to a PDF file. I have many graphs (200 for now) as I am drawing using PROC SGPLOT and BY statement. I searched online for the solution but all of them involve manually indicating the position of each graphs which is not ideal in my case. Is there a solution where I can tell SAS to print 4 graphs into 1 page instead of 1 big graph per page?

My code is:

proc sgplot data=prices;
by stock;
series x=date y=price;
series x=date y= volume/y2axis;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You may want to consider SGPANEL instead of SGPLOT and use the By variable Stock as a Panelby variable. You can specify the number of columns of (across graphs) and an appropriate number of rows of graphs would be made.

 

Try this and see if it gets close to what you want:

proc sgpanel data=prices;
   panelby stock /columns=2;
   series x=date y=price;
   series x=date y= volume/y2axis;
run;

There are a number of options on laying out the appearance depending on data.

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Have you looked at the ODS LAYOUT GRIDDED statement?

somebody
Lapis Lazuli | Level 10

I did try it. but could not get it to work. I tried:

ods pdf file = "graphs.pdf" startpage=never; 
ods layout gridded columns=2; proc sgplot data=prices; by stock; series x=date y=price; series x=date y= volume/y2axis; run; ods layout end; ods pdf close;

I got 4 graphs per page which is nice but they are all in 1 columns. I would like to get 2x2 or 3x3 graphs. That is 3 columns and 3 rows. 

ChrisNZ
Tourmaline | Level 20

No this?

ods layout gridded columns=2 rows=2;
ballardw
Super User

You may want to consider SGPANEL instead of SGPLOT and use the By variable Stock as a Panelby variable. You can specify the number of columns of (across graphs) and an appropriate number of rows of graphs would be made.

 

Try this and see if it gets close to what you want:

proc sgpanel data=prices;
   panelby stock /columns=2;
   series x=date y=price;
   series x=date y= volume/y2axis;
run;

There are a number of options on laying out the appearance depending on data.

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
  • 4 replies
  • 875 views
  • 1 like
  • 3 in conversation