Lesson 13: Using the Output Delivery System to Create External

advertisement
Lesson 13: Using the Output Delivery System to Create External Files
Summary
Main Points
Opening and Closing ODS Destinations
ODS destination;
ODS destination CLOSE;
The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and
reproducing the output from SAS procedures and the DATA step.
Each file format that you can create has a corresponding ODS destination. To create a certain
type of output, you open the destination that is associated with that output type. When you
are finished using a destination, you can close it again.
The default ODS destination is the LISTING destination. Another ODS destination is the
HTML destination. SAS provides many other ODS destinations such as PDF, RTF, and
several destinations that create files that you can open in Excel: CSVALL, MSOFFICE2K,
and EXCELXP.
You use the ODS statement to open the destination for each type of formatted output you
want to create. To close a destination, you add the keyword CLOSE to the ODS statement,
after the destination. If you do not close a destination, it remains open until the end of the
SAS session.
Using ODS to Create HTML, PDF, and RTF Files
ODS destination FILE='file-specification';
ODS _ALL_ CLOSE;
You can view HTML files in the Results Viewer in SAS, or in Web browsers. You can view
and work with PDF files in Adobe software products. You can view and work with RTF files
in word processors.
You use the ODS statement to specify the file that you want to create. You can open one
destination at a time, or you can open multiple destinations at once by using several ODS
statements.
SAS® Programming 1: Essentials
Copyright © 2010 SAS Institute Inc., Cary, NC, USA. All rights reserved.
1
Lesson 13: Using the Output Delivery System to Create External Files
You can close all destinations in a single ODS statement by adding the _ALL_ keyword
instead of a keyword for a specific destination. However, if you close all of the destinations,
SAS cannot display output for any procedures. You should always leave one destination
open, such as the LISTING destination. You can follow the statement to close all destinations
with an additional ODS statement that opens the LISTING destination.
Applying Style Definitions to External Files
ODS destination FILE='file-specification'
STYLE=style-definition;
To further enhance the appearance of ouput in many types of external files, you can apply a
style definition to the file. A style definition describes how to display the presentation aspects
of SAS output such as colors and fonts.
By default, the HTML destination uses the Default style definition, the PDF destination uses
the Printer style destination, and the RTF destination uses the RTF style definition. You
cannot apply style definitions to listing output.
To specify a style definition for the output, you can add the STYLE= option to your ODS
statement.
Using ODS to Create Files that Open in Microsoft Excel
The CSVALL destination creates a CSV file that you can view in the SAS Program Editor
window or another text editor as well as in Excel.
The MSOFFICE2K destination creates an HTML file that you can view in a Web browser,
Microsoft Word, or Microsoft Excel.
The EXCELXP destination creates an XML file that you can open in Microsoft Excel.
SAS® Programming 1: Essentials
2
Lesson 13: Using the Output Delivery System to Create External Files
Sample Code
Windows: Replace my-file-path with the location where you stored the practice files.
UNIX and z/OS: Specify the fully qualified path in your operating environment.
ods
ods
ods
ods
html file='my-file-path\myreport.html' style=sasweb;
pdf file='my-file-path\myreport.pdf';
rtf file='my-file-path\myreport.rtf';
csvall file='my-file-path\myexcel.csv';
proc freq data=orion.sales;
tables Country;
run;
ods close _all_;
ods listing;
SAS® Programming 1: Essentials
3
Download