I am running macro gernerating PLOTS from PROC SGPLOT, and need
save the plots out with explicit filename/location.
How ? Any Help?
The code below seems generated the file somewhere. But I cannot find anywhere.
If put dir path, it complains.
25813 %let plotvar=vol_dif_wt_csum;
25814 title "var=&plotvar.";
25815 ods layout gridded columns=2 rows=2 advance=table;
25816 ods graphics /width=600px height=400px imagename="_TEST_" outputfmt=png ;
25817 proc sgplot data=_index_avg_cmp_f_4grp(where=( ind between &endind. -1000 and
25817! &endind.+100));
25818 by blw_flag abv_flag;
25819 series x=ind y=&plotvar. / lineattrs=( color=blue thickness=2 pattern=solid);
25820 series x=ind y=&indexout._orig / y2axis lineattrs=( color=red thickness=2
25820! pattern=solid);
25821 refline &endind./axis=x lineattrs=(color=blue thickness=2 pattern=solid);
25822 refline &refind./axis=x lineattrs=(color=lime thickness=1 pattern=solid);
25823 run;
25823! quit;
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.76 seconds
cpu time 0.14 seconds
NOTE: There were 1972 observations read from the data set WORK._INDEX_AVG_CMP_F_4GRP.
WHERE (ind>=6100 and ind<=7200);
25824 ods layout end;
25825 %let plotvar=vol_dif_wt_csum;
25826 title "var=&plotvar.";
25827 ods layout gridded columns=2 rows=2 advance=table;
25828 ods graphics /width=600px height=400px imagename="D:\_TEST_" outputfmt=png ;
WARNING: The IMAGENAME option or the output name contains invalid characters. D___TEST_ will be used
as the image name prefix.
25829 proc sgplot data=_index_avg_cmp_f_4grp(where=( ind between &endind. -1000 and
25829! &endind.+100));
25830 by blw_flag abv_flag;
25831 series x=ind y=&plotvar. / lineattrs=( color=blue thickness=2 pattern=solid);
25832 series x=ind y=&indexout._orig / y2axis lineattrs=( color=red thickness=2
25832! pattern=solid);
25833 refline &endind./axis=x lineattrs=(color=blue thickness=2 pattern=solid);
25834 refline &refind./axis=x lineattrs=(color=lime thickness=1 pattern=solid);
25835 run;
25835! quit;
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.44 seconds
cpu time 0.09 seconds
NOTE: There were 1972 observations read from the data set WORK._INDEX_AVG_CMP_F_4GRP.
WHERE (ind>=6100 and ind<=7200);
25836 ods layout end;
😓 This ?
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;
title;
ods _all_ close;
options nodate nonumber ;
options leftmargin="0.001in" rightmargin="0.001in" topmargin=1cm;
options papersize=(10.00in 8.50in);
ods printer printer=png300 file="c:\temp\dashboard.png" style=normalprinter nogtitle;
ods layout gridded columns=3 advance=bygroup column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=3.00in noborder ;
proc sgplot data=_temp;
by grp1 grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
ods layout end;
ods printer close;
Hardly possible to suggest something useful without knowing the code of the macro.
The ods gpath option may be used to set the location images are stored, see https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatug/p0cmojsdkiab8cn1k2qk3rp3a8s0.htm for details.
My code generates 2*2 plot. How to Save the 2*2 into one file?! Thanks,
saving the grid plot created with high resolution 300 dpi - SAS Support Communities
Check this:
ods _all_ close; options nodate nonumber; options leftmargin="0.001in" rightmargin="0.001in"; options papersize=(7.35in 3.00in); title "Sales Dashboard"; ods printer printer=png300 file="dashboard.png" style=normalprinter;
Thanks. But still have issue.
The picture is saved out. But only one out of n-by-M.
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;quit;
ods _all_ close;
options nodate nonumber;
options leftmargin="0.001in" rightmargin="0.001in";
options papersize=(7.35in 3.00in);
ods printer printer=png300 file="dashboard.png" style=normalprinter;
proc sgplot data=_temp;
by grp1 grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
Even just the code from the link. It does not show up right.
data heart;
set sashelp.heart;
if (weight_status eq '') then weight_status="Unknown";
run;
proc sort data=heart; by weight_status; run;
ods printer printer=png300 file="bygroups.png" style=normalprinter;
ods layout gridded columns=2 rows=2 advance=bygroup
column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=3.5in;
title "#byval1";
proc sgplot data=heart noautolegend uniform=xscale;
by weight_status;
yaxis offsetmin=0.05;
histogram cholesterol;
density cholesterol;
fringe cholesterol;
run;
ods layout end;
ods printer close;
😓 This ?
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;
title;
ods _all_ close;
options nodate nonumber ;
options leftmargin="0.001in" rightmargin="0.001in" topmargin=1cm;
options papersize=(10.00in 8.50in);
ods printer printer=png300 file="c:\temp\dashboard.png" style=normalprinter nogtitle;
ods layout gridded columns=3 advance=bygroup column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=3.00in noborder ;
proc sgplot data=_temp;
by grp1 grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
ods layout end;
ods printer close;
Thanks. This is IT.
How to set ODS to the default, BTW?!
Run the code below. It says "WARNING: No output destinations active." and no output in SAS.
26305 proc sgplot data=_temp;
26306 by grp1 grp2;
26307 series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
26308 run;
26308! quit;
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.09 seconds
cpu time 0.03 seconds
WARNING: No output destinations active.
NOTE: There were 900 observations read from the data set WORK._TEMP.
For example, if you want to open HTML ODS destination :
ods html; ods graphics on; proc sgplot data=sashelp.class; scatter x=weight y=height; run;
7 ods html;
NOTE: 正在写入 HTML Body(主体)文件: sashtml.htm
8 ods graphics on;
9 proc sgplot data=sashelp.class;
10 scatter x=weight y=height;
11 run;
NOTE: “PROCEDURE SGPLOT”所用时间(总处理时间):
实际时间 1.17 秒
CPU 时间 0.34 秒
NOTE: 从数据集 SASHELP.CLASS. 读取了 19 个观测
For example, if you only want PDF ODS, you could close all these ODS firstly and open PDF secondly, then you would only have PDF .
ods _all_ close; ods pdf file='c:\temp\temp.pdf'; proc sgplot data=sashelp.class; scatter x=weight y=height; run; ods pdf close;
P.S. For SAS the default ODS is HTML . You could set other default ODS at somewhere in configure menu, but I've never done that before.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.