- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Solved: Re: How to 2X2 Chart ?! - SAS Support Communities
I asked to how to merge plots into one. It works. Still now, get one more quest, how to save the merged picture
explicitly with a specified filename/location, such as c:\myPicture\_today_pic_01.jpg/png ?!
ods layout gridded columns=2 rows=2 advance=proc;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_1 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_2 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_3 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_4 x=cycle;
run;
ods layout end;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think the best solution is using GTL within PROC TEMPLATE .
If it is simple scatter plot, you could try proc sgscatter.
data temp; do x=1 to 20; y1=ranuni(1); y2=10*ranuni(2); y3=100*ranuni(3); y4=1000*ranuni(4); output; end; run; ods listing gpath='c:\temp\'; ods graphics/reset=index imagename='today_pic_01' imagefmt=png; proc sgscatter data=temp; plot (y1-y4)*x; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The given SAS codes generate the plot with default filename/directory. I like to save it into a specified filename/location though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
30096 ods graphics on / reset imagename="new file name" imagefmt =jpeg;
30097 ods listing gpath = '%temp%';
30098 proc sgplot data=sashelp.class;
30099 scatter x=WEIGHT y=HEIGHT;
30100 run;
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.25 seconds
cpu time 0.09 seconds
NOTE: Listing image output written to C:\Users\ADMINI~1\AppData\Local\Temp\2\new file name1.jpeg.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
imagename="new file name" works on single plot (PROC SGPLOT) above. BUT I like to save 4-into-1 picture.
Also how to add a title-line on 4-into-1 picture?!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think the best solution is using GTL within PROC TEMPLATE .
If it is simple scatter plot, you could try proc sgscatter.
data temp; do x=1 to 20; y1=ranuni(1); y2=10*ranuni(2); y3=100*ranuni(3); y4=1000*ranuni(4); output; end; run; ods listing gpath='c:\temp\'; ods graphics/reset=index imagename='today_pic_01' imagefmt=png; proc sgscatter data=temp; plot (y1-y4)*x; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I agree with @Ksharp that, with this particular example, there is a lot of value in using PROC SGSCATTER instead. However, I thought it would be good to show everyone here how you can take the ODS LAYOUT example you had and turn it into a single PNG file.
Basically, you can use the ODS PRINTER destination with a PRINTER of PNG or PNG300 to write all of the output into the one image. The key is setting the PAPERSIZE (i.e the image size) and the content sizes to fit in the paper size. The FILE option can be used to specify the path and filename for the image. Here is an example using the ODS LAYOUT content you posted:
ods _all_ close;
options nodate nonumber;
options papersize=(7.35in 5.40in);
options leftmargin="0.001in" rightmargin="0.001in";
title;
ods printer printer=png file="composite.png";
ods layout gridded columns=2 rows=2 advance=proc
column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=3.5in;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_1 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_2 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_3 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_4 x=cycle;
run;
ods layout end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC SGSCATTER could be a solution in some cases, but there could be other uses of ODS LAYOUT GRIDDED where one plot is a histogram and the next plot is a series plot, and so on, and PROC SGSCATTER is not a solution (and in fact, I have used ODS LAYOUT GRIDDED like I just explained where they are not all scatterplots).
So this code is very helpful.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content