By default, SAS returns a very comprehensive amount of information in the output from its procedures. It is common for an analysis to involve a procedure run separately for groups within a dataset or for a list of variables. Output from this kind of repetitive analysis can be difficult to navigate scrolling through the output window. Writing SAS output to .pdf and .html files provides a way to view the output in a way that is easy to navigate using bookmarks. We will use the hsb2 dataset in the examples.
Sending output to a .pdf file
The output delivery system (ods) can generate a .pdf file that includes bookmarks for tables within the output. Below, we run a regression model separately for each of the four race categories in our data. Before the proc reg, we first sort the data by race and then open a .pdf file to which output is written. When we are done, we close the .pdf.
proc sort data = hsb2; by race; run; ods pdf file="d:\reg1.pdf"; proc reg data = hsb2; by race; model write = female read; run; quit; ods pdf close;
We can open the our .pdf file and use the bookmarks to jump to output from each race and, within each race, jump to specific output tables.
So far, we have used the default settings for our .pdf file. SAS offers several standard styles from which we can choose and, if none of them are to your liking, you can (with some effort) specify your preferences for all of the components that go into a style to create your own. Some of the standard styles are color variations on the default, but some have a different look altogether. If you indicate “style = minimal”, the output in your .pdf file will look like an output window with boxes around the blocks of output. If you indicate “style = theme”, the blocks of output have fewer lines and the headers are more formatted than those in the “minimal” style.
ods pdf file="d:\reg1.pdf" style = minimal; proc reg data = oarc.hsb2; by race; model write = female read; run; quit; ods pdf close;
ods pdf file="d:\reg1.pdf" style = theme; proc reg data = oarc.hsb2; by race; model write = female read; run; quit; ods pdf close;
Going beyond changing the overall style, there are some other ways in which you can control the look and organization of the .pdf file. For example, you can add a table of contents to the beginning of your file indicating which output appears on which page with the contents option. If the bookmarks displayed by default are too detailed for you, you can change the number of levels displayed with the pdftoc option. The usual titles and subtitles you can add to SAS output are reflected in your .pdf as well as any options you indicate in an options statement like removing the date and time or making the output left-justified instead of centered.
Below we create a table of contents and limit the number of bookmark levels to 2 and use the options and title statements in SAS.
options nodate nonumber nocenter; title "OARC SAS FAQ"; title2 "Output to PDF"; ods pdf file="d:\reg1.pdf" contents = yes pdftoc = 2; proc reg data = oarc.hsb2; by race; model write = female read; run; quit; ods pdf close;
For more details on customizing .pdf files using ods, see the following SAS papers:
Sending output to a .html file
NOTE: The code in this section generates files that can be opened in Internet Explorer. We did not have success opening these files in other browsers.
Just as it can generate a .pdf file, the Output Delivery System (ods) can generate .html files for SAS output. Again, we run a regression model separately for each of the four race categories in our data. Before running our regression, we open a .html file to which output is written. When we are done, we close the .html file.
ods html file = 'd:\body1.html'; proc reg data = hsb2; by race; model write = female read; run; quit; ods html close;
We can open this file up in Internet Explorer and scroll through our output.
If we want to be able to jump to specific parts of our output, we can easily add a contents bar. Instead of creating a single .html file, we will be creating several: the “body” of the page that contains the output, the “contents” that links to parts of the body, and a “frame” that combines the two. To view the contents as a side bar to the body, we will open the frame file.
ods html body = 'd:\body1.html' contents = 'd:\contents.html' frame = 'd:\main.html'; proc reg data = hsb2; by race; model write = female read; run; quit; ods html close;
As with .pdf files, you can choose from the standard SAS templates or create your own to customize the look of the generated file. This is only the tip of the SAS-to-HTML iceberg, but already we have seen an easy way to navigate long SAS output.