Introduction

Welcome to Edition 8 of Making SAS Accessible to Everyone. After learning how to create and interpret data reports in Edition 7, we now focus on how to automate and export those reports using SAS’s Output Delivery System (ODS).

ODS allows you to generate and share reports in a variety of professional formats, such as PDF, Excel, RTF (Word), and HTML. These features are critical for delivering insights to collaborators, stakeholders, or clients, particularly those who do not work directly in SAS.


1. Understanding ODS Basics

ODS gives you precise control over the format, layout, and destination of SAS output.

Basic Structure:

ODS <format> FILE="filepath" <style-options>;
    ... SAS procedures ...
ODS <format> CLOSE;
  • Replace <format> with PDF, EXCEL, RTF, or HTML.
  • You can include style options like STYLE=JOURNAL, STYLE=PEARL, etc.
  • All output between FILE=... and CLOSE is directed to the selected format.

2. Creating PDF Reports

PDF is great for final, printable reports.

ODS PDF FILE="C:/Reports/demographic_summary.pdf" STYLE=JOURNAL;

TITLE "Demographic Summary Report";
PROC MEANS DATA=work.demographics;
    VAR Age Height Weight;
RUN;

PROC FREQ DATA=work.demographics;
    TABLES Gender AgeGroup;
RUN;

ODS PDF CLOSE;

Notes:

  • PDF reports can contain multiple procedures.
  • STYLE=JOURNAL gives a clean, academic appearance.

3. Creating Excel Reports with Multiple Sheets

ODS EXCEL FILE="C:/Reports/summary.xlsx" STYLE=PEARL;

ODS EXCEL OPTIONS(SHEET_NAME="Descriptive Stats");
PROC MEANS DATA=work.demographics;
    VAR Age Height Weight;
RUN;

ODS EXCEL OPTIONS(SHEET_NAME="Categorical Data");
PROC FREQ DATA=work.demographics;
    TABLES Gender;
RUN;

ODS EXCEL CLOSE;

Benefits:

  • Each call to ODS EXCEL OPTIONS(SHEET_NAME=...) creates a new worksheet.
  • Easy to distribute and open with Excel.
  • Supports styles like PEARL, DOVE, and MEADOW.

4. Creating HTML and RTF Reports

HTML Reports

Ideal for sharing results on intranet sites or embedding into dashboards.

ODS HTML FILE="C:/Reports/report.html" STYLE=HTMLBLUE;
PROC PRINT DATA=work.demographics;
RUN;
ODS HTML CLOSE;

RTF (Word-Compatible Reports)

Great for inclusion in Word documents.

ODS RTF FILE="C:/Reports/report.docx" STYLE=PRINTER;
PROC REPORT DATA=work.demographics NOWD;
RUN;
ODS RTF CLOSE;

5. Controlling Output with ODS SELECT and EXCLUDE

Focus only on relevant parts of a procedure:

ODS PDF FILE="C:/Reports/univariate_output.pdf";
ODS SELECT Moments BasicMeasures;
PROC UNIVARIATE DATA=work.demographics;
    VAR Age;
RUN;
ODS PDF CLOSE;

Use ODS TRACE ON; to identify table names produced by a procedure.

ODS TRACE ON;
PROC UNIVARIATE DATA=work.demographics;
    VAR Age;
RUN;
ODS TRACE OFF;

This helps you fine-tune what appears in your reports.


6. Exporting Data with PROC EXPORT

If you need to share clean datasets for use outside SAS:

To CSV:

PROC EXPORT DATA=work.summary
    OUTFILE="C:/Reports/summary.csv"
    DBMS=CSV REPLACE;
RUN;

To Excel:

PROC EXPORT DATA=work.summary
    OUTFILE="C:/Reports/summary.xlsx"
    DBMS=XLSX REPLACE;
RUN;

Use these when you want to export data, not formatted reports.


Conclusion

In Edition 8, you learned how to:

  • Generate PDF, Excel, HTML, and Word-compatible reports using ODS
  • Apply different styles to professionalize your outputs
  • Customize report content with ODS SELECT and ODS TRACE
  • Export data to CSV and Excel using PROC EXPORT

These tools empower you to communicate results effectively and automate the creation of high-quality, reproducible reports.


What’s Next

In Edition 9, we will take our first steps into Using SQL in SAS.


Stay professional and stay curious with 3 D Statistical Learning.

Special thanks to Dr. Dany Djeudeu for demystifying statistical computing and making it accessible to everyone.