As we saw in the last section, in order to create HTML output, you simply open the HTML destination using the HTML keyword in the ODS statement. Simple enough! In this section, we'll extend what we learned there by:
- creating HTML output from multiple procedures at once;
- creating HTML output with a table of contents; and
- using options to specify links and paths.
Example 24.3: Creating HTML Output from Multiple Procedures Section
The following program uses the penngolf data set to simultaneously create HTML output from the PRINT and REPORT procedures:
ODS LISTING CLOSE;
ODS HTML body = 'C:\yourdrivename\Stat481WC\12ods\output\golf2.html';
PROC PRINT data = stat481.penngolf NOOBS;
title 'Some Par 72 Pennsylvania Golf Courses';
ID name;
var year type yards;
where par = 72;
RUN;
PROC REPORT data = stat481.penngolf NOWINDOWS HEADLINE HEADSKIP;
title 'Average Size of Some PA Courses';
column type par yards;
define type /group;
define yards / analysis mean format = 6.1 width = 10;
define par / analysis mean format = 4.1 width = 10;
RUN;
ODS HTML CLOSE;
ODS LISTING;
Before launching and running the program, let's take a quick look at the code to make sure we know what it's doing:
- The first ODS statement again tells SAS to close the Listing destination.
- The second ODS statement tells SAS to open the HTML destination and to save the HTML output generated by the code to the specified file name. Note that rather than using the ODS HTML statement's FILE= option, we used the BODY= option to tell SAS where to save the HTML output. The two options are interchangeable. That is, the BODY= option is an alias for the FILE= option.
- Then, we use the PRINT procedure to tell SAS to print some information about the par 72 golf courses.
- Then, we use the REPORT procedure to tell SAS to calculate the average yardage and average par for each of the four types of golf courses.
- The third ODS statement tells SAS to close the HTML destination so that we can access the created HTML file.
- And, the last ODS statement tells SAS to re-open the Listing destination.
Now, go ahead and launch the SAS program. Again, you'll have to edit the first ODS HTML statement to reflect where you would like your HTML file stored. Then, run the SAS program, and review the output as it appears in the SAS Results Viewer. You should first see the output from the PRINT procedure:
Some Par7 2 Pennsylvania Golf Courses
Name | Year | Type | Par | Yards |
---|---|---|---|---|
Toftrees | 1968 | Resort | 72 | 7018 |
Penn State Blue | 1921 | Public | 72 | 6525 |
Lewistown CC | . | Private | 72 | 6779 |
Mount Airy Lodge | 1972 | Resort | 72 | 7123 |
and then the output from the REPORT procedure:
Average Size of Some PA Courses
Type | Par | Yards |
---|---|---|
Private | 71.3 | 6553.3 |
Public | 72.0 | 6525.0 |
Resort | 72.0 | 7070.5 |
SemiPri | 70.6 | 6394.8 |
You should also note that SAS saves the generated HTML output in the file specified in the first ODS HTML statement. To see the file, go to the folder in which you told SAS to store the HTML file. Here's what my folder looks like after running the program:
When we run the code in Example 24.2, SAS creates the golf.html file. And, when we run the above code from Example 24.3, SAS creates the golf2.html file. For some reason, I have trouble opening either file with Mozilla Firefox, but am able to do so with Internet Explorer. To do so, right-click on the golf2.html file (or whatever you've called the file), and select Open With... Internet Explorer. You should see the same output that SAS displays in the SAS Results Viewer. It is this physical golf2.html file though that you could easily post to a public website or e-mail to someone else.
Example 24.4: Creating HTML Output with a Table of Contents Section
When you have a program that creates many pages of output, you might find it useful for SAS to create a table of contents for the output. The following program is identical to the previous program, except the first ODS HTML statement has been modified to tell SAS to create a table of contents for the output that SAS generates:
ODS LISTING CLOSE;
ODS HTML body='C:\yourdrivename\Stat481WC\12ods\output\golf3.html'
contents = 'C:\yourdrivename\Stat481WC\12ods\output\golf3toc.html'
frame = 'C:\yourdrivename\Stat481WC\12ods\output\golf3frame.html';
PROC PRINT data = stat481.penngolf NOOBS;
title 'Some Par 72 Pennsylvania Golf Courses';
ID name;
var year type yards;
where par = 72;
RUN;
PROC REPORT data = stat481.penngolf NOWINDOWS HEADLINE HEADSKIP;
title 'Average Size of Some PA Courses';
column type par yards;
define type /group;
define yards / analysis mean format = 6.1 width = 10;
define par / analysis mean format = 4.1 width = 10;
RUN;
ODS HTML CLOSE;
ODS LISTING;
Since the code is almost identical to the previous program, the only code that needs explanation this time around is the first ODS HTML statement. As before, the BODY= option tells SAS where we want to store the HTML output generated from the subsequent PRINT and REPORT procedures. Not surprisingly, the CONTENTS= option tells SAS where we want to store the table of contents. The FRAME= option gives SAS a place to store the HTML page containing the integrated table of contents and body file. Note that the FRAME= option and the CONTENTS= option go together. That is, if you include the FRAME= option in your ODS HTML statement, you must also include the CONTENTS= option.
Okay, go ahead and launch the SAS program, and edit the first ODS HTML statement to reflect where you would like your HTML files stored. Then, run the SAS program, and review the output as it appears in the SAS Results Viewer. Look at this! The output looks no different than the output from the previous example. The only thing you should see in the SAS Results Viewer is the body file golf3.html. To see the results along with the table of contents and table of pages, you have to open the frame file golf3frame.html (or whatever you call the frame file). To do so, go to the folder in which you told SAS to store the HTML files. Here's what my folder looks like now after running the program:
If you click on the golf3.html file (or whatever you called the body file), and select Open With... Internet Explorer, you should again see the results of the PRINT and REPORT procedures. If you right-click on the golf3toc.html file (or whatever you called the table of contents file) and select Open With... Internet Explorer, you should see the table of contents with links to each procedure output in the body file. It's the frame file that you should find the most useful in this situation. If you right-click on the golf3frame.html file (or whatever you called the frame file) and select Open With... Internet Explorer, you should see the table of contents and the body file integrated into one page. If you click on the links in the table of contents, you can see how SAS moves you to the relevant output.
Using Options to Specify Links and Paths Section
If you're not familiar with at least the concept of Hypertext Markup Language (HTML), then you would find this topic quite challenging. In short, HTML is the behind-the-scenes language that tells your web browser what to display. If you go to any web page, and view the page source, you'll see the HTML code that displays the web page that you are viewing. (Using Mozilla's Firefox browser, you can view the page source by selecting View and then Page Source. Using an Internet Explorer browser, you can view the page source by selecting Page and then View Source). This topic concerns the pathnames that SAS creates when it creates HTML output files for you. If the pathnames aren't well specified, then you will have trouble sharing your SAS-created HTML output files with others.
It is not fair to expect students who are not already familiar with HTML to fully understand this topic. On the other hand, students who are planning on taking the SAS 9 Base Programmer Certification Exam might find a question or two concerning this topic on the exam. For those students, I recommend using the SAS Certification Prep Guide which explains using options to specify links and paths. For the purpose of this course, I can not, and therefore will not, expect students to master this topic. Of course, if you are planning on taking the exam, and you have questions concerning these options, please don't hesitate to ask them.