Skip to Main Content

SAS Tutorials: Exporting Results to Word or PDF

Exporting SAS Output to Word or PDF with the SAS Output Delivery System (ODS)

When running your SAS program, you may want to extract a table from your SAS output to include in a manuscript you're authoring in Microsoft Word. Or, you may want to save your output to a PDF file to share with a colleague.

New SAS users may be tempted to simply copy and paste the tables from the Output window into another program, but there is a much easier way: the SAS Output Delivery System (ODS).

You can use the ODS to directly save SAS output as an HTML file, a PDF file, an RTF file (which can be imported into Word), and other file types. You can also modify the look of the output by editing the color scheme, font, and size of the output. In this tutorial we will show the basic usage of ODS, but it is extremely customizable! To learn more about how ODS works, you can visit SAS’s ODS Documentation .

Some tips for using ODS:

  • You can run multiple procedures between opening and closing the ODS statements.  All of the procedures will be in the same file.
  • The full list of recognized style names can be found within the SAS ODS documentation section on Customizing the Presentation of a Report .

Exporting to a PDF file

The ODS PDF command can be used to create PDF output from your SAS procedures. The general syntax of ODS PDF is:

ODS PDF FILE = 'C:/Users/path-to-file/output-file-name.pdf' STYLE= statistical;
<...SAS procedures to write to file...>
ODS PDF CLOSE;

The first line triggers the creation of the new output file:

  • The ODS PDF statement starts the Output Delivery System and tells SAS to create a PDF output file.
  • The FILE= option specifies a full file path (folder directory and output file name) where SAS should write the PDF output.
  • The STYLE= option changes the aesthetics of the output. Some commonly used styles are Statistical, Minimal, Journal, and Analysis.

The last line of code -- ODS PDF CLOSE; -- tells SAS to stop writing the output to the PDF file. This line is very important; without it, SAS will continue to write to the PDF file.

Any PROC step(s) you put between the first and last lines will have their output written to the PDF file. If you include multiple PROC steps between the first and last lines, all of them will be included in the same PDF file; so if you want separate PDF outputs for each PROC step, you will need to set up multiple ODS PDF/ODS PDF CLOSE statements.

When you are satisfied with your code, select the lines of syntax and click Run. You can view the PDF in two ways: 1) you can click on the PDF in the Results window, or 2) you can go to the file folder on your computer where you told SAS to store the PDF file. If you do not include the option of a specific style (i.e., Statistical, Minimal), your output will use the Default style as shown below. 

Example

For this example, we are telling SAS to save the results of the frequency table for the variable Athlete.

ODS PDF FILE = 'C:/Users/path-to-output/AthleteTable.pdf' STYLE= statistical;
PROC FREQ DATA = WORK.sample;
  TABLE athlete;
RUN;
ODS PDF CLOSE;

The tables in the resulting PDF file should look like the following (when the various style options are applied):

Default Style:

The default style using ODS output.

Statistical Style:

 

The statistical style using ODS output.

Journal Style:

The journal style using ODS output

Analysis Style:

 

The Analysis style using ODS output.

Exporting to Word

The ODS RTF command can be used to create RTF (or "rich text") output from your SAS procedures, which can be opened and edited using Microsoft Word. The general syntax of ODS RTF is:

ODS RTF FILE = 'C:/Users/path-to-file/output-file-name.rtf' STYLE= minimal;
<...SAS procedures to write to file...>
ODS RTF CLOSE;

The first line triggers the creation of the new output file:

  • The ODS RTF statement starts the Output Delivery System and tells SAS to create an RTF output file.
  • The FILE= option specifies a full file path (folder directory and output file name) where SAS should write the RTF output.
  • The STYLE= option changes the aesthetics of the output. Some commonly used styles are Statistical, Minimal, Journal, and Analysis.

The last line of code -- ODS RTF CLOSE; -- tells SAS to stop writing the output to the RTF file. This line is very important; without it, SAS will continue to write to the RTF file.

Any PROC step(s) you put between the first and last lines will have their output written to the RTF file. If you include multiple PROC steps between the first and last lines, all of them will be included in the same RTF file; so if you want separate RTF outputs for each PROC step, you will need to set up multiple ODS RTF/ODS RTF CLOSE statements.

When you are satisfied with your code, select the lines of syntax and click Run. You can view the Word document in two ways: 1) you can click on the rtf file in the Results window, or 2) you can go to the file folder on your computer where you told SAS to store the file, right click on the file, hover your mouse over Open With and select Microsoft Word.

Example

For this example, we are telling SAS to store the results of the frequency table for the variable, Athlete, followed by a cross-tabulation table for Athlete and Gender in the file. We will also apply the Minimal style.

ODS RTF FILE = 'C:/Users/path-to-output/AthleteTables.rtf' STYLE= minimal;
PROC FREQ DATA = WORK.sample;
  TABLE athlete;
RUN;

PROC FREQ DATA = WORK.sample;
  TABLE athlete*gender;
RUN;
ODS RTF CLOSE;

The tables in the resulting RTF file should look like the following:

The Minimal style using ODS output to Word.

The Minimal style using ODS output for Word for the crosstabulation table of Athlete and Gender.

Tutorial Feedback