# Saving SAS Output Files

SAS Notes

## Default Output (not saved)

As you work in SAS, the ordinary statistical tables and graphs output by your SAS procedures is displayed in the Results Viewer and stored in a temporary HTML file.

proc means data=sashelp.class;
run;

The Log tells you these results are in a file, but it is coy about the file's location.

NOTE: Writing HTML Body file: sashtml.htm
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE MEANS used (Total process time):
real time           0.22 seconds
cpu time            0.12 seconds

If your results consist purely of tables and text, you can use the SAS interface to re-save this file in a more obvious and convenient location. Click File - Save As, browse to a location, specify a file name, and pick one of the "Webpage" file types. You save everything in the Results Viewer.

If your results include graphs, as is very often the case, you can still save everything via the SAS interface. Click File - Save As, browse to a location, specify a file name, and then pick the "Webpage, complete" file type. In addition to the HTML file containing your tables and text, a folder with the same name as your file will have each of your graphs saved as a .png image file.

## HTML Output (saved)

You can automate saving your HTML output with an ODS HTML statement ("ODS" is an acronym for Output Delivery System). There are three basic options to be aware of: - file or body - path - gpath

The file or body option specifies the name of the file to save. The path option specifies where to save that file. And the gpath options determines where graphs are saved (by default, they are saved in the path location).

To save our PROC MEANS would be

ods html file="example.html" path="U:\" gpath="U:\example";
proc means data=sashelp.class;
run;

proc sgplot data=sashelp.class;
vbox height / group=sex;
run;

HTML OUTPUT FILE

## Text (Listing) Output

To save this as a text file, use ODS listing output. Here, the file option includes the directory (rather than using path), and we again have a gpath option for graphics files.

ods listing file="u:\example.lst" gpath="u:\";
proc means data=sashelp.class;
run;

proc sgplot data=sashelp.class;
vbox height / group=sex;
run;

(See the Details, below, to get a more useful version of text output.)

LISTING OUTPUT FILE

LISTING OUTPUT GRAPH

To stop writing to a file ("destination") you close it.

ods html close;
ods listing close;

## MS-Word and Adobe Acrobat Output

Other output desinations work similarly. For MS Word and Adobe Acrobat documents, there is no gpath option because graphs are included in the primary file.

ods rtf file="SaveSASOutput\example.rtf"; /* MS-Word format */
ods pdf file="SaveSASOutput\example.pdf"; /* Adobe PDF format */

proc means data=sashelp.class;
run;

proc sgplot data=sashelp.class;
vbox height / group=sex;
run;

ods rtf close; /* cannot be viewed until closed */
ods pdf close;

MS-WORD OUTPUT FILE

PDF OUTPUT FILE

## Details Worth Knowing

A few extra details are worth mentioning.

### Style

Both HTML and RTF output have shaded cells for the table headers. This is "style". You can change the style.

ods rtf file="SaveSASOutput\example-styled.rtf" style=minimal;
ods html file="SaveSASOutput\example-styled.html" style=minimal;

proc means data=sashelp.class;
run;

ods rtf close;
ods html close;

MS-WORD STYLED OUTPUT

HTML STYLED OUTPUT FILE

### Text Fonts

Listing output makes use of the SAS Monospace character font. However this is a mess when viewed on computers without SAS, or in software that does not use fonts (e.g. Notepad). You can make your text files portable with the formchar system option;

options formchar="|----|+|---+=|-/\<>*";
ods listing file="u:\example.lst";

proc means data=sashelp.class;
run;

ods listing close;

LISTING OUTPUT, BETTER FONT

### The OUTPUT Window

One other basic thing to know about listing output is that you can send it to the Output window. This can be noticeably faster than other forms of output, but cannot show you graphs.;

ods listing;
proc means data=sashelp.class;
run;

### Multiple Destinations

SAS will happily write to multiple files simultaneously. If you check the Results pane when multiple destinations are "open", you will find that SAS added the PROC MEANs table to several files!

ods listing;
ods rtf file="u:\example.rtf"; /* MS-Word format */
ods pdf file="u:\example.pdf";
proc means data=sashelp.class;
run;

proc sgplot data=sashelp.class;
vbox height / group=sex;
run;
ods listing close;
ods rtf close;
ods pdf close;