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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

View solution in original post

7 REPLIES 7
SASJedi
SAS Super FREQ

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?

Check out my Jedi SAS Tricks for SAS Users
DanH_sas
SAS Super FREQ

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

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

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.

DanH_sas
SAS Super FREQ

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?

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
This suggestion did the trick. .
SASJedi
SAS Super FREQ
That's an awesome blog!
Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1330 views
  • 6 likes
  • 4 in conversation