When you use SAS to create graph and Output Delivery System (ODS) output, you might want to write your graph and ODS output to the SAS Work location (also known as the SAS Work directory). When you do this, any graph and ODS output that you write to the SAS Work location is deleted upon normal termination of the current SAS session.
The recommended method for doing this is to first use the following %LET statement to define a macro variable whose value resolves to the current SAS Work directory:
%let workdir=%trim(%sysfunc(pathname(work)));
Once you create the WORKDIR macro variable above, you can then use it in place of a hardcoded directory name when creating your graph and ODS output. For example, the following sample code writes a PNG file with the name sastest.png to the current Work directory:
%let workdir=%trim(%sysfunc(pathname(work)));
ods _all_ close;
ods listing;
filename grafout "&workdir./sastest.png";
goptions reset=goptions device=png gsfname=grafout;
proc gchart data=sashelp.class;
where sex="F";
vbar age / sumvar=weight type=mean subgroup=age
nolegend discrete;
run;
quit;
This example demonstrates how to write HTML and graph output to the Work directory using the ODS HTML statement with the SGPLOT procedure:
%let workdir=%trim(%sysfunc(pathname(work)));
ods _all_ close;
ods html path = "&workdir" (url=none)
file = "sgplot.html";
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
discretelegend;
run;
ods html close;
ods listing;
While the example above uses PROC SGPLOT, the same technique works with any graph or non-graph SAS procedure that produces output.
If you want to write graphics output to the Work location using a SAS/GRAPH® Statistical Graphics procedure or ODS Graphics without using the ODS HTML statement, use the GPATH= option in the ODS LISTING statement, as shown below:
%let workdir=%trim(%sysfunc(pathname(work)));
ods _all_ close;
ods listing gpath="&workdir";
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
discretelegend;
run;
You can also use this technique when writing PDF output to the Work directory. For example:
%let workdir=%trim(%sysfunc(pathname(work)));
ods _all_ close;
ods pdf file="&workdir./sastest.pdf";
proc print data=sashelp.class; run;
ods pdf close;
ods listing;
This technique can be used when writing RTF output to the Work directory, as shown below:
%let workdir=%trim(%sysfunc(pathname(work)));
ods _all_ close;
ods rtf file="&workdir./sastest.rtf";
proc print data=sashelp.class; run;
ods rtf close;
ods listing;