Thus far, we have used ODS statements to tell SAS to create HTML output. As mentioned earlier, we can also use ODS statements to tell SAS to create other kinds of output. In this section, we'll take a look at two examples in which we tell SAS to make different kinds of output. In the first example, we make RTF output that can be easily copied into Microsoft Word. In the second example, we make PDF output that can be then sent to a high-resolution printer.
Example 24.5: Using ODS Statements to Create RTF Output Section
The following program tells SAS to print a subset of the penngolf data set and when doing so to send the output to an RTF destination:
ODS LISTING CLOSE;
ODS RTF file = 'C:\Simon\Stat481WC\sp09\12ods\output\golf5.rtf'
BODYTITLE;
PROC PRINT data = stat481.penngolf NOOBS;
title 'Some Par 72 Pennsylvania Golf Courses';
ID name;
var year type yards;
where par = 72;
RUN;
ODS RTF CLOSE;
ODS LISTING
As you can see, to tell SAS to send output to the RTF destination, we simply use the RTF keyword in an ODS statement. By default, titles and footnotes are put into Word headers and footers. The BODYTITLE option in the ODS RTF statement tells SAS to instead put titles and footnotes in the main part of the RTF document. Note that the second-to-last ODS statement tells SAS to close the RTF destination, while the last ODS statement tells SAS again to re-open the Listing destination.
Launch the SAS program. Then, edit the ODS RTF statement to reflect where you would like your RTF file stored. Then, run the SAS program. When you do so, a pop-up window that looks something like this should appear:
If you select Open, you'll see the contents of the golf5.rtf file (or whatever you called it) in the SAS Results Viewer. You can then easily copy the contents of the Results Viewer into a Word document. Alternatively, you can go to the folder in which you told SAS to store your RTF file:
and double-click on the file to open it in Word.
Example 12.6: Using ODS Statements to Create PDF Output Section
The following program does exactly the same thing as the previous program, except the output here is sent to a PDF file:
ODS LISTING CLOSE;
ODS PDF file = 'C:\Simon\Stat481WC\sp09\12ods\output\golf6.pdf';
PROC PRINT data = stat481.penngolf NOOBS;
title 'Some Par 72 Pennsylvania Golf Courses';
ID name;
var year type yards;
where par = 72;
RUN;
ODS PDF CLOSE;
ODS LISTING;
Pretty straightforward... as you can see, to tell SAS to send output to the PDF destination, we simply use the PDF keyword in an ODS statement. Note again that the second-to-last ODS statement tells SAS to close the PDF destination, while the last ODS statement tells SAS again to re-open the Listing destination.
Launch the SAS program. Then, edit the ODS PDF statement to reflect where you would like your PDF file stored. Then, run the SAS program. Again, there are a couple of things you can do to view the resulting PDF file. First, you can review the PDF file as it appears in the SAS Results Viewer. Alternatively, you can go to the folder in which you told SAS to store your PDF file:
and double-click on the file to open it.