9.2 Generating PDF, HTML, & RTF Output Destinations

Key Takeaways

  • Opening an ODS destination requires ODS <destination> FILE='file-path'; and must be closed with ODS <destination> CLOSE; to release file locks.
  • Multiple ODS destinations (e.g., HTML, PDF, RTF) can be open simultaneously, receiving procedure output in parallel without re-executing steps.
  • The STYLE= option on an ODS destination statement applies built-in or custom CSS/printer style templates (e.g., STYLE=HTMLBlue, STYLE=Sapphire, STYLE=Journal).
  • Closing the LISTING destination (ODS LISTING CLOSE;) prevents SAS from generating redundant monospaced text output, improving execution performance.
  • HTML destination sub-options such as BODY=, FRAME=, CONTENTS=, and PAGE= allow the creation of multi-frame web reports with automated tables of contents.
Last updated: August 2026

9.2 Generating PDF, HTML, & RTF Output Destinations

The true power of ODS lies in its ability to format raw procedure output into polished, publication-ready documents. By opening specific ODS destinations, SAS programmers can generate web pages (HTML), printable vector documents (PDF), and editable word-processor documents (RTF) simultaneously from a single execution of SAS code.


ODS Destination Statement Lifecycle

Managing ODS destinations follows a strict syntax lifecycle:

  1. Open the destination and specify the target output file path and options.
  2. Execute SAS DATA steps or procedure steps (e.g., PROC PRINT, PROC REPORT, PROC MEANS).
  3. Close the destination to flush output buffers, write file headers/footers, and release OS file locks.
+-------------------------------------------------------------+
| 1. Open Destination: ODS <destination> FILE='path' <opts>; |
+-------------------------------------------------------------+
                              |
                              v
+-------------------------------------------------------------+
| 2. Execute SAS Steps: PROC PRINT / PROC REPORT / PROC MEANS  |
+-------------------------------------------------------------+
                              |
                              v
+-------------------------------------------------------------+
| 3. Close Destination: ODS <destination> CLOSE;             |
+-------------------------------------------------------------+

Basic Syntax Pattern

ODS <destination> FILE = "file-specification" <options>;

/* SAS Code Generating Reports */

ODS <destination> CLOSE;

[!WARNING] If you omit the ODS <destination> CLOSE; statement, the output file remains locked by the SAS session. You will be unable to open, move, or edit the resulting file in external applications like Adobe Acrobat or Microsoft Word until the destination is closed or the SAS session terminates.


Generating Core Destinations: HTML, PDF, and RTF

SAS supports numerous file destinations. The three core document destinations tested on the SAS Base Programming exam are HTML, PDF, and RTF.

1. The ODS HTML Destination

The ODS HTML destination produces web-compatible HTML files. In modern SAS interfaces (such as SAS Studio or Enterprise Guide), HTML is often the default viewing destination.

ods html file="C:\reports\sales_summary.html" style=HTMLBlue;

proc print data=sashelp.class;
run;

ods html close;

Advanced ODS HTML Options (Multi-Frame Reports)

ODS HTML allows you to split output into a frame structure with an automated table of contents:

ods html body     = "C:\reports\body.html"
         contents = "C:\reports\toc.html"
         frame    = "C:\reports\main_frame.html"
         style    = Meadow;

proc report data=sashelp.shoes;
   column Region Sales Inventory;
   define Region / group;
run;

ods html close;
ODS HTML File OptionPurpose
BODY=Specifies the HTML file containing the actual procedure tables and graphics.
CONTENTS=Specifies the HTML file containing a hyperlinked Table of Contents (TOC).
FRAME=Specifies an HTML frame file that integrates the contents and body into a split window.
PAGE=Specifies an HTML file containing links to each new page of output.

2. The ODS PDF Destination

The ODS PDF destination produces high-resolution, vector-based PDF documents ideal for printing, archiving, and distribution.

ods pdf file="C:\reports\annual_report.pdf" 
        style=Pearl 
        pdftoc=1 
        dpi=300;

title "Company Sales Analysis";
proc means data=sashelp.prdsale sum;
   class Country;
   var Actual Predict;
run;

ods pdf close;

Key ODS PDF Options

  • FILE = "filename.pdf": Required path for PDF output.
  • PDFTOC = 1 | 2: Enables bookmark outline trees in PDF readers up to specified expansion depth.
  • UNIFORM: Maintains consistent column widths across multiple pages or tables.
  • STARTPAGE = YES | NO | NOW: Controls page breaking behavior between procedures.

3. The ODS RTF Destination

The ODS RTF destination produces Rich Text Format documents that can be opened and edited natively in Microsoft Word.

ods rtf file="C:\reports\clinical_trial.rtf" style=Journal;

proc freq data=sashelp.heart;
   tables Status * Sex / chisq;
run;

ods rtf close;

Applying Styles with the STYLE= Option

Every ODS destination uses a visual style template to determine fonts, background colors, cell padding, table borders, and line spacing. SAS includes dozens of built-in styles.

You apply a style using the STYLE= option on the ODS destination opening statement:

ODS PDF FILE="report.pdf" STYLE=Sapphire;

Commonly Tested Built-in SAS Styles

Style NameIntended Use / Visual Characteristics
HTMLBlueDefault modern blue-themed style for web and screen presentation.
PearlClean, high-contrast light theme popular for PDF reports.
SapphireDeep blue accents with crisp table borders.
JournalBlack-and-white, minimal monospaced/serif style designed for academic publications.
PrinterHigh-contrast grayscale optimized for black-and-white paper printing.

Managing Default Destinations & Performance Optimization

Default SAS Environment Behavior

Depending on how SAS is executed, certain destinations are opened automatically at session startup:

  • SAS Windowing Environment (Display Manager): LISTING and/or HTML may be open by default.
  • SAS Studio: ODS HTML5 destination is managed automatically by the application container.
  • Batch Mode: ODS LISTING is active by default.

Disabling the LISTING Destination for Efficiency

The legacy LISTING destination formats output as traditional fixed-width text files. When generating large reports in HTML or PDF, leaving LISTING open causes SAS to format output twice (once for LISTING and once for PDF/HTML), consuming unnecessary CPU and memory.

It is standard SAS best practice to close LISTING before executing production report pipelines:

/* 1. Turn off LISTING to conserve CPU resources */
ods listing close;

/* 2. Open desired production destinations */
ods pdf file="C:\reports\large_report.pdf" style=Pearl;
ods html file="C:\reports\large_report.html" style=HTMLBlue;

/* 3. Run production reporting procedures */
proc report data=sashelp.demographics;
run;

/* 4. Close production destinations */
ods pdf close;
ods html close;

/* 5. Re-open LISTING for normal interactive work */
ods listing;

Destination Management Syntax Comparison

ActionODS Command Syntax
Open PDF with custom styleODS PDF FILE='output.pdf' STYLE=Pearl;
Close PDF destinationODS PDF CLOSE;
Close LISTING destinationODS LISTING CLOSE;
Re-open LISTING destinationODS LISTING;
Query open destinationsODS DESTALL; / Check SAS Log
Test Your Knowledge

What occurs if a SAS programmer runs ODS PDF FILE="C:\report.pdf"; followed by a PROC PRINT step, but forgets to include ODS PDF CLOSE;?

A
B
C
D
Test Your Knowledge

A programmer needs to generate an editable report that can be directly modified using Microsoft Word, while applying a black-and-white publication style named Journal. Which statement is correct?

A
B
C
D
Test Your Knowledge

Which ODS HTML option specifies the file that contains an automatically generated hyperlinked Table of Contents?

A
B
C
D
Test Your Knowledge

Why is executing ODS LISTING CLOSE; recommended when generating large PDF or HTML reports in production SAS programs?

A
B
C
D