Course 5: SAS Output Delivery System (ODS)
Welcome to the SAS Output Delivery System (ODS) Certificate Program! This course focuses on mastering ODS to generate, customize, and automate professional reports and visualizations in formats like HTML, PDF, RTF, and Excel. Over one week, you will learn to control output destinations, generate reports in multiple formats, customize output appearance, create visualizations with ODS Graphics, and automate reporting with macros. Designed for learners with basic SAS knowledge, this course equips you with skills to produce polished outputs for data communication.
Objective: By the end of the course, learners will be proficient in using ODS to create, customize, and automate reports and visualizations, enabling efficient data sharing with stakeholders.
Scope: The course covers ODS fundamentals, report generation, output customization, ODS Graphics, and automation, with hands-on exercises and quizzes.
Day 1: Introduction to ODS
Introduction: The SAS Output Delivery System (ODS) is a powerful tool that allows users to control, format, and export SAS analysis results. ODS enables output from SAS procedures and data steps to be directed into formats like HTML, PDF, RTF, and Excel, facilitating professional report creation and sharing with diverse audiences. This session introduces ODS concepts, syntax, and its role in modern SAS reporting.
Learning Objectives: By the end of this session, you will be able to understand the purpose and capabilities of ODS, use basic ODS statements to control output format and destination, generate output in HTML, PDF, and RTF formats, open and close ODS destinations to manage reporting workflows, and recognize ODS benefits for automating and enhancing SAS reporting.
Scope: This session focuses on foundational ODS elements, including opening/closing ODS destinations, specifying output formats, and directing procedure results to files.
Background Information: Before ODS, SAS output was limited to plain text listings. ODS introduced flexibility to capture, format, and export results in various styles and file types. ODS destinations tailor output to audience needs, and ODS statements provide precise control over report content.
Hands-On Example:
Using a dataset sales_data
, generate summary statistics in different formats.
Example 1: HTML Output
ods html file="sales_summary.html"; proc means data=sales_data; var Sales Profit; run; ods html close;
Example 2: PDF Output
ods pdf file="sales_summary.pdf"; proc means data=sales_data; var Sales Profit; run; ods pdf close;
Example 3: RTF (Word) Output
ods rtf file="sales_summary.rtf"; proc means data=sales_data; var Sales Profit; run; ods rtf close;
Example 4: Multiple Destinations
ods html file="summary.html"; ods pdf file="summary.pdf"; proc freq data=sales_data; tables Region; run; ods html close; ods pdf close;
Example 5: Close All Destinations
ods _all_ close;
Interpretation: Examples 1–3 direct PROC MEANS output to HTML, PDF, and RTF files. Example 4 shows simultaneous output to multiple destinations. Example 5 ensures all ODS destinations are closed, preventing file corruption.
Supplemental Information:
Discussion Points:
- How does ODS enhance flexibility in SAS reporting?
- What are the benefits of generating output in multiple formats?
- When is sending output to multiple destinations useful?
- What are best practices for managing ODS destinations?
- How can ODS automate routine reporting tasks?
Day 2: Generating Reports in Different Formats
Introduction: ODS excels at generating reports in various formats, enabling integration into business documents, presentations, and web platforms. This session explores generating, customizing, and managing reports in HTML, PDF, RTF, and Excel formats for professional sharing.
Learning Objectives: By the end of this session, you will be able to generate SAS reports in HTML, PDF, RTF, and Excel, understand syntax and options for ODS destinations, customize file names and locations, combine multiple procedures into a single report, and apply best practices for organizing reports.
Scope: This session emphasizes practical techniques for producing reports in different formats, ensuring accessibility for diverse audiences.
Background Information: ODS destinations route SAS output to specific file types, each with unique syntax and options for tailoring results.
Hands-On Example:
Using sales_data
, create reports in various formats.
Example 1: HTML Report
ods html file="sales_report.html" style=statistical; proc freq data=sales_data; tables Region Product; run; ods html close;
Example 2: PDF Report
ods pdf file="sales_report.pdf" style=journal; proc means data=sales_data; class Region; var Sales Profit; run; ods pdf close;
Example 3: RTF (Word) Report
ods rtf file="sales_report.rtf" style=printer; proc tabulate data=sales_data; class Region Product; var Sales; table Region, Product*Sales*mean; run; ods rtf close;
Example 4: Excel Report
ods excel file="sales_report.xlsx" options(sheet_name="Summary"); proc means data=sales_data; class Product; var Sales; run; ods excel close;
Example 5: Combined PDF Report
ods pdf file="full_report.pdf"; title "Sales Summary"; proc means data=sales_data; var Sales Profit; run; title "Sales by Region"; proc freq data=sales_data; tables Region; run; ods pdf close;
Interpretation: Examples 1–4 generate reports in HTML, PDF, RTF, and Excel with customized styles or options. Example 5 combines multiple procedures into a single PDF.
Supplemental Information:
Discussion Points:
- What are the advantages of generating reports in different formats?
- How do ODS styles impact report appearance?
- When should you combine multiple procedures in one file?
- What are best practices for naming output files?
- How can you ensure reports are accessible to audiences?
Day 3: Customizing Output Appearance
Introduction: Creating visually appealing reports is critical for effective communication. ODS provides options for customizing output appearance, including styles, titles, footnotes, and selective output control, ensuring professional reports.
Learning Objectives: By the end of this session, you will be able to apply ODS styles, add and format titles and footnotes, use ODS SELECT and ODS EXCLUDE to control output objects, customize table layout, and create visually consistent reports.
Scope: This session focuses on enhancing SAS output’s visual quality using ODS styles, titles, footnotes, and selective output control.
Background Information: ODS styles are templates controlling colors, fonts, and borders. Titles and footnotes add context, while ODS SELECT and ODS EXCLUDE fine-tune report content.
Hands-On Example:
Using sales_data
, create customized reports.
Example 1: Styled Output
ods pdf file="styled_report.pdf" style=journal; proc means data=sales_data; class Region; var Sales Profit; run; ods pdf close;
Example 2: Titles and Footnotes
ods html file="titled_report.html" style=statistical; title1 "Quarterly Sales Report"; title2 "Prepared by the Analytics Team"; footnote1 "Confidential - For Internal Use Only"; proc freq data=sales_data; tables Region; run; footnote1; ods html close;
Example 3: Selective Output
ods pdf file="selective_output.pdf"; ods select Summary; proc means data=sales_data; class Product; var Sales; run; ods pdf close;
Example 4: Excluding Output
ods rtf file="exclude_output.rtf"; ods exclude ExtremeObs; proc univariate data=sales_data; var Profit; run; ods rtf close;
Example 5: Custom Table Appearance
ods html file="custom_table.html" style=meadow; proc print data=sales_data noobs label; var Region Product Sales; label Sales = "Total Sales (USD)"; run; ods html close;
Interpretation: Example 1 applies a professional style. Example 2 adds titles and footnotes. Examples 3 and 4 use ODS SELECT and EXCLUDE to focus output. Example 5 customizes table appearance.
Supplemental Information:
Discussion Points:
- How do ODS styles improve report readability?
- When would you use ODS SELECT or ODS EXCLUDE?
- What are the benefits of titles and footnotes?
- How can you ensure visual consistency across reports?
- What are best practices for customizing SAS output?
Day 4: ODS Graphics and Visualizations
Introduction: Visualizations highlight data trends and patterns. ODS integrates with SAS graphics procedures to produce high-quality charts and plots in various formats. This session introduces ODS Graphics for creating and exporting visualizations.
Learning Objectives: By the end of this session, you will be able to enable and control ODS Graphics, generate visualizations like bar charts and scatter plots, export graphics to HTML, PDF, RTF, and Excel, customize graphic appearance, and integrate visualizations into reports.
Scope: This session covers creating and exporting visualizations using ODS Graphics with PROC SGPLOT.
Background Information: ODS Graphics produces statistical graphics, enabled by default in modern SAS, and can be controlled with ODS GRAPHICS statements.
Hands-On Example:
Using sales_data
, create and export visualizations.
Example 1: Bar Chart (PDF)
ods graphics on; ods pdf file="bar_chart.pdf"; proc sgplot data=sales_data; vbar Region / response=Sales stat=mean; title "Average Sales by Region"; run; ods pdf close; ods graphics off;
Example 2: Histogram (HTML)
ods graphics on; ods html file="histogram.html"; proc sgplot data=sales_data; histogram Profit; title "Distribution of Profit"; run; ods html close; ods graphics off;
Example 3: Scatter Plot (RTF)
ods graphics on; ods rtf file="scatter_plot.rtf"; proc sgplot data=sales_data; scatter x=Advertising y=Sales / group=Region; title "Sales vs. Advertising by Region"; run; ods rtf close; ods graphics off;
Example 4: Styled Graphics (PDF)
ods graphics on; ods pdf file="styled_graphics.pdf" style=meadow; proc sgplot data=sales_data; series x=Month y=Sales / group=Region; title "Monthly Sales Trends by Region"; run; ods pdf close; ods graphics off;
Example 5: Multiple Graphics (Excel)
ods graphics on; ods excel file="visual_report.xlsx"; proc sgplot data=sales_data; vbar Product / response=Sales stat=sum; title "Total Sales by Product"; run; proc sgplot data=sales_data; boxplot x=Region y=Profit; title "Profit Distribution by Region"; run; ods excel close; ods graphics off;
Interpretation: Examples 1–3 create bar charts, histograms, and scatter plots, exported to PDF, HTML, and RTF. Example 4 applies a custom style. Example 5 exports multiple graphics to Excel.
Supplemental Information:
- ODS Graphics Tips and Tricks (Lex Jansen)
- Getting Started with ODS Graphics (UCLA)
- SAS ODS Graphics Video Tutorial
Discussion Points:
- How does ODS Graphics enhance report impact?
- What are the benefits of exporting graphics to different formats?
- When should you use custom styles for visualizations?
- How can you ensure consistency in graphic appearance?
- What are best practices for integrating graphics with tabular output?
Day 5: Automating and Exporting Results
Introduction: ODS automation saves time and ensures consistency in reporting. Combining ODS with macro programming and dynamic file naming creates efficient workflows for professional report generation and distribution.
Learning Objectives: By the end of this session, you will be able to automate report creation using ODS and macros, dynamically generate file names, batch process results, schedule automated workflows, and apply best practices for organizing automated output.
Scope: This session covers automation strategies, including macro loops, dynamic file naming, and batch processing.
Background Information: ODS automation integrates ODS statements with macro programming to control report generation. Macro variables and loops enable parameter-driven reports.
Hands-On Example:
Using sales_data
, automate reports for regions and years.
Example 1: Multiple Regions
%let regions = North South East West; %macro region_reports; %local i region; %let i = 1; %let region = %scan(®ions, &i); %do %while (®ion ne ); ods pdf file="®ion._sales_report.pdf"; proc means data=sales_data; where Region = "®ion"; var Sales Profit; title "Sales Report for ®ion Region"; run; ods pdf close; %let i = %eval(&i + 1); %let region = %scan(®ions, &i); %end; %mend region_reports; %region_reports
Example 2: Dynamic File Naming
%let year = 2024; ods excel file="sales_report_&year..xlsx"; proc means data=sales_data; where Year = &year; var Sales Profit; title "Sales Report for &year"; run; ods excel close;
Example 3: Batch Yearly Reports
%macro yearly_reports(start, end); %do y = &start %to &end; ods html file="sales_&y..html"; proc means data=sales_data; where Year = &y; var Sales Profit; title "Sales Report for &y"; run; ods html close; %end; %mend yearly_reports; %yearly_reports(2021, 2023)
Example 4: Multi-Format Exports
%let region = North; ods pdf file="®ion._report.pdf"; ods rtf file="®ion._report.rtf"; proc freq data=sales_data; where Region = "®ion"; tables Product; title "Product Frequency for ®ion Region"; run; ods pdf close; ods rtf close;
Interpretation: Example 1 automates PDF reports for each region. Example 2 uses macro variables for dynamic Excel file naming. Example 3 batches HTML reports for multiple years. Example 4 exports results in PDF and RTF.
Supplemental Information:
Discussion Points:
- What are the benefits of automating report generation?
- How does dynamic file naming improve output organization?
- When is batch processing useful for report exports?
- What are best practices for scheduling automated SAS jobs?
- How can you ensure accuracy in automated reports?
Daily Quiz
Practice Lab
Select an environment to practice coding exercises. Use SAS OnDemand for Academics for a free SAS programming environment.
Exercise
Click the "Exercise" link in the sidebar to download the exercise.txt file containing 20 SAS ODS exercises with solutions. Use these exercises to practice generating, customizing, and automating reports in SAS.
Grade
Day 1 Score: Not completed
Day 2 Score: Not completed
Day 3 Score: Not completed
Day 4 Score: Not completed
Day 5 Score: Not completed
Overall Average Score: Not calculated
Overall Grade: Not calculated
Generate Certificate
Click the button below to generate your certificate for completing the course.