In previous lessons you created HTML reports and viewed them in SAS.
In this class, and in your future endeavors, you will likely want to create your output in formats
other than HTML and / or save your output in external files that you can use outside of SAS.
To create external files, you work with the SAS output delivery system, or ODS.
In this lesson you learn to use ODS statements to send the output from SAS procedures to many types of external files.
Manipulating SAS’s Output Delivery System with ODS statements allows you greater control
over the end products your SAS programs create.
The focus of this lesson is the use of ODS statements to store your output in a variety of external files.
ODS also makes it easier to change the appearance of your reports; however, we will not cover changing styles in this lecture.
Each file format that you can create has a corresponding ODS destination.
Here the word “destination” may be somewhat confusing.
Although the word destination sort of implies a location for the file,
that is not its purpose.
In this case, destination simply means the type of file you want to create.
Later, you will tell SAS where to create it.
For each type of formatted output you want to create, you use an ODS statement to open that destination.
After the keyword ODS, you specify the destination that you want to open.
The destination can consist of just a keyword, or keyword plus options for the destination you want to use.
To create a certain type of output, you open the destination associated with that output type.
When you are finished using a destination, you can close it again.
If you open a destination and do not close it, the destination remains open until the end of your session.
Up to this point you have mainly viewed HTML output in the results viewer window within SAS.
However, in this lesson you will learn how to use ODS to save your output directly to HTML files, as well as use the PDF and RTF destinations.
To close a destination you simply add the keyword CLOSE to the ODS statement after the destination.
The three ODS destination formats you will learn about today are listed in this table.
HTML stands for Hypertext Markup Language.
In addition to viewing HTML files in the results viewer window in SAS,
you can also view them in web browsers such as Internet Explorer, Google Chrome, or Apple’s Safari.
PDF stands for Portable Document Format.
You can view and work with PDF files in Adobe software products, Apple’s Preview, and others.
RTF stands for Rich Text Format.
You can view and work with RTF files in word processors such as Microsoft Word.
Now that you know how to open and close destinations, or tell SAS what type of file you want to create,
sending output to an external file requires only a small modification to your code.
Following the destination, you just need to tell SAS where to create the file,
and what to name it, using the FILE equals option.
Make sure to enclose the file specification in quotation marks.
Here are examples of ODS statements that create external HTML, PDF, and RTF files.
In these examples, notice that the files specification consists of a path and a file name.
You can open one destination at a time,or multiple destinations at once.
Just remember, as shown here, you must close every individual ODS destination you open with a separate ODS CLOSE statement.
Or you must use the ODS CLOSE statement with the _ALL_ keyword.
But remember, SAS cannot display the output for any procedure when all destinations are closed.
In this demonstration you will learn how to create reports as HTML, PDF, and RTF files, and send them to external files.
In this first example you are creating a list report of the height_and_weight data set.
As you’ve already seen, when you submit your program, an html list report is displayed in the Results Viewer Window.
This works well for viewing reports within SAS, but what if you want to send this report to someone else, or view it after you close SAS?
You have two options.
SAS will let you save this report as an external file in a couple different formats.
You do this by clicking save in the file drop down menu, or by clicking the save tool in the toolbar.
Another, more flexible, way to save this file is with an ODS statement.
This program is identical to the program above, except that you’ve added ODS statements that
tell SAS to save all output produced between here and here to the html file named report 1.
And your telling SAS the location where you want that file to be saved – in this case on the desktop.
When you submit the program, an html file called report 1 is created on the desktop.
Double clicking that file opens your list report in a new web browser window.
This is really handy for many things, including saving results during your homework
assignments into files that can easily be submitted for grading.
And you can also use ODS statements to save output to PDF and RTF files.
In this program you are saving your list report as a html, pdf, and rtf file on your desktop,
and closing all three destinations with the _all_ keyword.
When you submit this program, all three files appear on the desktop, and on this computer,
Microsoft Word opens automatically and displays the rtf list report.
Finally, you have your print procedure one more time without any ODS statements.
When you submit the program, it appears as though nothing happens.
But, when you check the log window there is a Warning that no output destination is active.
Question: Why are you getting this warning?
You are getting this warning because you closed all ods destinations at the end of your last program,
but you didn’t open any new destinations before submitting this program.
Therefore, SAS does not know what format to create the list report in, or where to create it.
In order to get SAS to display your html reports in the Results Viewer Window again
you must reopen the html destination.
This concludes your brief introduction to the Output Delivery System in SAS. You will use ODS
statements throughout this course, so make sure you get comfortable with them.