I'm making a lot of box plots (270) and sending them to an .rtf file. However, the default is to put one graph per page, which takes up far too much room. Ideally, I'd like to be able to control the number and layout of graphs per page--for example, "3 rows and 4 columns" or "4 rows and 5 columns", etc. so that I can get fewer pages. Does anyone know of a way to do this?
Here is my macro which creates a single (jittered) box plot:
%macro box_plots (variable_title=, variable=);
proc template;
define statgraph &variable.;
begingraph;
entryTitle "Serum Samples: &variable_title. by &phenotype_title.";
layout overlay / xaxisopts=(display=(tickvalues)
linearOpts=(tickvalueSequence=(start=1 increment=1 end=&num_of_groups.)
tickValueFormat=groupfmt.))
yaxisopts=(label="Concentration (uM)");
scatterPlot x=eval(0.08*rannor(569154)+group_n) y=&variable. /
markerAttrs=(symbol=circle) group=group_n datalabel=&variable._lab
dataTransparency=0;
boxplot x=group_n y=&variable. / display=(caps mean median)
meanAttrs=(symbol=diamond color=black);
endlayout;
endgraph;
end;
run;
proc sgrender template=&variable. data=&variable.;
run;
%mend box_plots;
And here is my code which outputs the graphs to an RTF file:
ods rtf file="O:\Path\3b All Analytes by Exposure and Sex Box Plots &sysdate. ZA.rtf";
%box_plots(variable=c_1, variable_title=C0);
/*269 more iterations of this macro with different variables*/
ods rtf close;
My first thought would be to look at SGPANEL and appropriate panel by statement / variables added to your data if needed. Group like topics and use specified numbers of columns and rows. The HBOX or VBOX will do box plots with different oreintation.
I agree with ballardw. I addition, if you do not have any natural grouping variables in your data, you can make up an indexing variable (1, 2, 3, etc.) for the data you want in each cell. Starting in SAS 9.4, we added a NOHEADER option on the PANELBY statement to turn off the cell headers. For this case, you can use the option to supress the display of the indexing variable, which has no meaning, while giving you control over your grid layout.
Hope this helps!
Dan
Thank you for the feedback! Unfortunately, I don't think SGPANEL will help here because I have to use a graph template since I'm doing jittered box plots, and I'm not sure how to use panels for this kind of graph. Additionally, all of the 270 variables are on wildly different scales which I think is a problem for SGPANEL (and it isn't convenient to look for variables with similar enough scales to group together). Unless you know of a solution to these dilemmas?
For SAS 9.4, Jittering support was added to the SCATTER statement in SGPLOT and SGPANEL, as was the ability to overlay the SCATTERs and BOXPLOTs. However, if your box plots are not in comparitive ranges, then SGPANEL will not work well for you. There are ways to make only one axis uniform and not the other, but that requires a layout of either one column or one row to be most effective.
On a side note, if you generate PDF instead of RTF, you could use ODS LAYOUT to do exactly what you want. Is that format possible for you?
Yes, a PDF would be just fine! I usually just use .rtf because it's easier for me. Could you tell me how to do this with a PDF? Thank you!
PDF is fine, could you tell me how to implement that solution? Thanks!
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!
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.