I am trying to put two histograms side by side, and the variables I'm using are different ones that do not lend themselves to using PROC SGPANEL. In the following code, I can produce the plot but not save an image file that has the two charts side by side. Instead, I get a separate image file for each histogram. I cannot find a solution in the documentation for ODS GRAPHICS...
ods listing gpath="C:\Figures\";
ods graphics / imagename="test" imagefmt=png;
ods layout gridded columns=2 advance=table;
ods noproctitle;
proc sgplot data=sashelp.cars;
histogram MPG_city;
run;
proc sgplot data=sashelp.cars;
histogram MPG_highway;
run;
ods select all;
ods proctitle;
ods layout end;
I did a blog post on how to write ODS LAYOUT output into a single image. Check out this post and let me know if you have any questions.
Thanks!
Dan
Each PROC SGPLOT step generates a graphic file containing the specified plot(s). ODS LAYOUT just specifies how they are laid out in the output destination. In a web page, the layout is accomplished in the HTML:
<table class="c layoutcontainer" cellspacing="30" cellpadding="0" border="0" summary="Layout table"> <col> <col> <tr class="layoutregion"> <td class="c layoutregion"> <div class="branch"><a name="IDX"/> <div> <div class="c"> <img alt="The SGPlot Procedure" src="test1.png" style=" height: 480px; width: 640px;" border="0" class="c"> </div> </div><br> </div> </td> <td class="c layoutregion"> <div class="branch"><a name="IDX1"/> <div> <div class="c"> <img alt="The SGPlot Procedure" src="test2.png" style=" height: 480px; width: 640px;" border="0" class="c"> </div> </div><br> </div> </table>
If you write the output to PDF instead, you can get a single file with the images side by side:
ods graphics / imagename="test" imagefmt=png;
ods noproctitle;
ods pdf file="C:temp\test.pdf";
ods layout gridded columns=2 advance=table;
ods region width=3in;
proc sgplot data=sashelp.cars;
histogram MPG_city;
run;
ods region width=3in;
proc sgplot data=sashelp.cars;
histogram MPG_highway;
run;
ods select all;
ods proctitle;
ods layout end;
ods pdf close;
Does that help?
I did a blog post on how to write ODS LAYOUT output into a single image. Check out this post and let me know if you have any questions.
Thanks!
Dan
That worked with some trial and error to get the settings right. The outputted plots have blue cell borders. Is there a way to control the cell borders for the layout? I could not see an option, but thought I would ask. These blue borders are not matching the style of other figures.
By default, ODS PRINTER will have a different style than HTML. Did you use the STYLE= option on the ODS PRINTER statement to force the style to be the same?
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.