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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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