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;
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.
Have you looked at the ODS LAYOUT GRIDDED statement?
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.