SAS makes it possible to save your statistical tables and graphs in many different forms, including text (ASCII) files, rich text (RTF or Word) files, PDF files, Excel tables, LaTeX files, HTML (web page) files, and for graphics a variety of graphics file formats. You can save your results to some of these output destinations using the SAS Display Manager, the standard graphical user interface. All of these output destinations can be reached via SAS commands as well.
If you are primarily interested in saving your tables and graphs in a Word file, skip ahead to the “RTF Output” section.
- New Default Output Settings
- How do I get my old defaults back?
- HTML Output Style
- HTML (& Graphics) File Locations
- RTF Output
- Combining Log and Listing Output
In version 9.3 or later of SAS, the default form of output changed from text (“Listing” output in SAS jargon) to HTML. Additionally, ODS graphics is now on by default, where previously it was off.
There are two main advantages to HTML output. First, you get statistical tables and graphs all integrated into one output stream. (This is also an advantage of RTF or PDF output.) Second, it makes it easy to cut-and-paste selected tables from SAS to Word without having to worry as much about formatting and using SAS monospace fonts in Word (also an advantage of RTF output). An advantage of using ODS graphics is that a good graphic can help you more quickly understand your data.
A disadvantage of ODS graphics is that creating all those graphics may slow down the execution of your SAS job. If your job creates large amounts of output, even HTML output can slow the job significantly.
There are two good ways to get Listing output and turn off HTML output and ODS graphics. One is to change your SAS registry settings (i.e. the things you get by clicking Tools, Options), the other is to put several commands in an autoexec file. Both will work every time you start a new SAS session, so you only need to make this change once.
Registry settings have the advantage that they are set through SAS’s menus and dialog boxes, so you don’t need to learn any new code. Autoexec files have the advantage that they are capable of executing any type of SAS command, and they are more likely to successfully carry over to a new version of SAS.
SAS Registry Settings
To change your registry settings to the old defaults, click on Tools, Options, Preferences, and then the Results tab.
Check Create listing, and uncheck both Create HTML and Use ODS Graphics. Click OK.
You will notice that it is possible to have both Listing and HTML output at the same time, although it is hard to image how that would be useful most of the time. There are a couple of other, useful settings that are discussed below.
If you use both 64-bit and 32-bit versions of SAS, you will need to make these changes once for each version. (Your settings for 32-bit SAS are saved in your U:\SAS folder. For 64-bit SAS they are in your U:\SAS64 folder.)
You can put commands you want to run at the beginning of every SAS session in a file named autoexec.sas in the root folder of your U:\ drive or in the SAS startup folder. For 32-bit SAS the SAS startup folder is U:\SAS, for 64-bit SAS it is U:\SAS64. These are otherwise just ordinary SAS command files. (If you use the appropriate startup folders you may have a different autoexec.sas for each version.)
A set of three commands will return you to the old output defaults:
ods html close;
ods graphics off;
(As with SAS registry settings, there are a number of other configurations you could consider here.)
If you are using HTML output, there are at least two reasons you might consider changing the default style of HTML output from htmlblue to something else. First, if you are simply cutting-and-pasting a few tables from your results to a Word document, you lose all the internal table lines, the cell borders. (The color scheme shouldn't concern you too much if you cut-and-paste, because the color does not paste into Word.) Second, if you are saving complete files of HTML output and editing them in some other software like Word, the blue color scheme will then carry over into your final document.
You can change the output style either via the registry (Click Tools, Options, Preferences, Results) or your autoexec.sas file. Two styles you might consider are minimal and journal.
ods html style=minimal;
By default your HTML and ODS graphics files are saved in your temporary WORK library, and are deleted when you close your SAS session. As with Listing output, the Log, and the Program Editor, you can save your HTML results through the menus: File, Save As. You can save your HTML output either as an archive (a single file) or as regular HTML (which may be a collection of files if you have any graphics).
You can also automatically save your HTML output to a permanent location, either through registry settings or through autoexec code:
ods html path='u:\' body='sashtml.htm' style=journal;
Note, however, that the settings or code above will overwrite any existing file(s) with the same name(s) when you start a new SAS session: using File, Save As is a safer practice for most of us.
If you are interested in using your results in a Word document, why not just save them in a Word-friendly format to begin with?
As you would expect by now, there are two ways to get your results into an RTF document: via the display manager interface, or via ods commands. However, in the case of RTF output these produce quite different documents, and most people will prefer the RTF documents produced by ods commands.
To save an RTF file using the menus, first note that you can only save Listing output (from the Output window). You cannot save HTML output or graphics this way. With the Output window active, select File, Save As, then change the file type to RTF, and save your file.
The resulting document is essentially a text file that has been formatted with SAS monospace fonts. Tables are not really tables, they are drawn with font characters, and if you try to use this document on a computer that does not have SAS installed, the document will look awful.
The better way to save RTF files is through the pair of ODS commands:
ods rtf file='u:\example.rtf' style=journal;
/* your SAS PROCs go here */
ods rtf close;
The resulting document has tables that can be edited as tables in Word (so changing font face, size, or spacing does not misalign your table), and uses a Times Roman font.
When you are trying to debug a lengthy SAS command file, sometimes it is useful to have both the SAS code and the results it produces in one output stream (like in Stata or SPSS), so that you can see which output table matches just which PROC.
To do this, you must have Listing output turned on, and redirect your output as well as your log to a file.
proc printto print='u:\singlefile.txt’ log=’u:\singlefile.txt';
/* your SAS PROCs go here */
proc printto; /*Send your output and log back to their default windows */
Last Revised: 12/8/2011