Chapter 10. Producing HTML Output

Overview

Introduction

In previous chapters, you've seen both traditional SAS listing output and HTML output. When you set options to create HTML output, SAS uses Output Delivery System (ODS) statements to generate the output.

Using ODS, you can create, customize, and manage HTML output by submitting programming statements. After you create HTML files, you can view them using Internet Explorer, Netscape Navigator, or any Web browser that fully supports HTML 3.2.

This chapter shows you how to create and view HTML output using ODS. You also learn how to apply styles to ODS output.

Introduction
Introduction

Objectives

In this chapter, you learn to

  • open and close ODS destinations

  • create a simple HTML file with the output of one or more procedures

  • create HTML output with a linked table of contents in a frame

  • use options to specify links and file paths

  • view HTML output

  • apply styles to HTML output.

The Output Delivery System

Before you learn to write ODS programming statements, it's helpful to understand a little about ODS.

Advantages of ODS

ODS gives you formatting options and makes procedure output much more flexible. With ODS, you can easily create output in a variety of formats, including

  • HTML output

    Advantages of ODS
  • an output data set of procedure results

    Advantages of ODS
  • traditional SAS listing output

    Advantages of ODS

Also, ODS holds your output in its component parts (data and table definition) so that numerical data retains its full precision.

Let's see how ODS creates output.

How ODS Works

When you submit your ODS statements and the SAS program that creates your output, ODS does the following:

  1. ODS creates your output in the form of output objects.

    Each output object contains the results of a procedure or DATA step (the data component) and can also contain information about how to render the results (the table definition).

    How ODS Works
  2. ODS sends the output object to the ODS destination(s) that you specify and creates formatted output as specified by the destination. For example, when the Listing and HTML destinations are open, ODS creates Listing and HTML output.

    How ODS Works
  3. ODS creates a link to each output object in the Results window and identifies each output object by the appropriate icon.

    How ODS Works

    Let's take a look at how you open various ODS destinations.

Opening and Closing ODS Destinations

ODS Destinations

You use ODS statements to specify destinations for your output and each destination creates a specific type of formatted output. The table below lists some of the ODS destinations that are currently supported.

This destination . . .

Produces . . .

HTML

output that is formatted in Hypertext Markup Language (HTML)

Listing

output that is formatted like traditional SAS procedure (listing) output

Markup Languages Family

output that is formatted using markup languages such as Extensible Markup Language (XML)

Document

a hierarchy of output objects that enables you to render multiple ODS output without rerunning procedures

Output

SAS data sets

Printer Family

output that is formatted for a high-resolution printer such as PostScript (PS), Portable Document Format (PDF), or Printer Control Language (PCL) files

RTF

Rich Text Format output for use with Microsoft Word

ODS Destinations

Using Statements to Open and Close ODS Destinations

For each type of formatted output you want to create, you use an ODS statement to open the destination. At the end of your program, you use another ODS statement to close the destination so that you can access your output.

You can issue ODS statements in any order, depending on whether you need to open or close the destination. Most ODS destinations are closed by default and you open them at the beginning of your program and close them at the end. The exception is the Listing destination, which is open by default.

Using Statements to Open and Close ODS Destinations

Example

The following program creates SAS listing output because the Listing destination is open by default. No other ODS destinations are open, so no other output formats are produced.

proc print data=sasuser.mydata;
run;

The following program produces HTML and listing output:

ods html body='c:mydata.html';
proc print data=sasuser.mydata;
run;
ods html close;
Example

Closing the Listing Destination

As you have learned, the Listing destination is open by default. Because open destinations use system resources, it's a good idea to close the Listing destination at the beginning of your program if you don't want to produce listing output. For example:

ods listing close;

The Listing destination remains closed until you end your current SAS session or until you re-open the destination. It's a good programming practice to reset ODS to listing output (the default setting) at the end of your programs. For example:

ods listing;

Example

The following program produces only HTML output:

ods listing close;
ods html body='c:mydata.html';
proc print data=sasuser.mydata;
run;
ods html close;
ods listing;

Closing Multiple ODS Destinations at Once

One of the features of ODS is that you can produce output in multiple formats at once by opening each ODS destination at the beginning of the program.

When you have more than one open ODS destination, you can use the keyword _ALL_ in the ODS CLOSE statement to close all open destinations at once.

Example

The program below opens the HTML and PDF destinations before the PROC step and closes all ODS destinations at the end of the program:

ods html file='HTML-file-pathname';
ods pdf file='PDF-file-pathname';

proc print data=sasuser.admit;
run;

ods _all_ close;
ods listing;

Notice that the last ODS statement reopens the Listing destination so that ODS returns to producing listing output for subsequent DATA or PROC steps in the current session.

Now that you have learned how to open and close ODS destinations, let's take a closer look at opening the HTML destination to create HTML output.

Creating Simple HTML Output

To create HTML output, you open the HTML destination using the ODS HTML statement.

Example

The program below creates PROC PRINT output in an HTML file. The BODY= option specifies the file F:admit.html in the Windows operating environment as the file that contains the PROC PRINT results.

ods listing close;
ods html body='f:admit.html';
proc print data=clinic.admit label;
   var sex age height weight actlevel;
   label actlevel='Activity Level';
run;
ods html close;
ods listing;

Notice that ODS statements close the Listing destination and open the HTML destination. Then, after the RUN statement, you close the HTML destination and open the Listing destination.

The HTML file admit.html contains the results of all procedure steps between the ODS HTML statement and ODS HTML CLOSE statement.

Example

Viewing Your HTML Output

If you're working in the Windows environment, when you submit the program, the body file will automatically appear in the SAS internal browser or your preferred Web browser, as specified in the Results tab of the Preferences window.

In other operating environments, you can double-click the corresponding link in the Results window to view the HTML output in your Web browser. If you don't have a Web browser in your operating environment, you can transfer the HTML files to an operating environment where you can view them.

When you specify a path and filename for your HTML results, the HTML file does not automatically open in SAS Enterprise Guide. Use Windows Explorer to locate the file you created and then double-click it to open it in your browser.

When you submit the program, two HTML results will appear in the Project window. One uses the HTML style that is active in SAS Enterprise Guide. The other uses the ODS statements from the code that you submitted and creates a temporary file labeled with the path and filename that you designated. It is similar in style to the actual HTML file that gets created in the location that you specify.

In this chapter, you will use Windows Explorer to locate the actual HTML file you created and then double-click it to open it in your browser.

When you submit the program, two HTML results appear in the Project window. One is the HTML output that is created by SAS Enterprise Guide ODS statements.The other uses the ODS statements from the code that you submitted and creates a temporary file labeled with the path and filename that you designated. It is similar in style to the actual HTML file that gets created in the location that you specify.

You can double-click the shortcut to open the HTML results in SAS Enterprise Guide, or you can right-click the shortcut and select Open with default-browser to open it in a browser. To see the actual file rather than the temporary file, you can use Windows Explorer to locate the HTML file you created and then double-click it to open it in your browser.

Creating HTML Output from Multiple Procedures

You can also use the ODS HTML statement to direct the results from multiple procedures to the same HTML file.

The program below generates HTML output for the PRINT and TABULATE procedures. The results for both procedures are saved to the file C:Recordsdata.html in the Windows environment. A link for each output object (one for each procedure) appears in the Results window.

You can also use the ODS HTML statement to direct the results from multiple procedures to the same HTML file.

The program below generates HTML output for the PRINT and TABULATE procedures. The results for both procedures are saved to the file C:Recordsdata.html.

ods listing close;
ods html body='c:
ecordsdata.html'; 
proc print data=clinic.admit label;
   var id sex age height weight actlevel;
   label actlevel='Activity Level';
run;
proc tabulate data=clinic.stress2;
   var resthr maxhr rechr;
   table min mean, resthr maxhr rechr;
run;
ods html close;
ods listing;

The following is a representation of the HTML file containing the results from the program above. Notice that the results from each procedure are appended.

Creating HTML Output from Multiple Procedures

Creating HTML Output with a Table of Contents

So far in this chapter, you've used the BODY= specification to create a simple HTML file containing your procedure output. Suppose you want to create an HTML file that has a table of contents with links to the output of each specific procedure. You can do this by specifying additional files in the ODS HTML statement.

Example

In the program below,

  • the BODY= specification creates data.html in the c: ecords directory. The body file contains the results of the two procedures.

  • the CONTENTS= specification creates toc.html in the c: ecords directory. The table of contents file has links to each procedure output in the body file.

  • the FRAME= specification creates frame.html in the c: ecords directory. The frame file integrates the table of contents and the body file.

    Example
ods listing close;
ods html body='c:
ecordsdata.html' 
         contents='c:
ecords	oc.html' 
         frame='c:
ecordsframe.html';
proc print data=clinic.admit label;
   var id sex age height weight actlevel;
   label actlevel='Activity Level';
run;
proc print data=clinic.stress2;
   var id resthr maxhr rechr;
run;
ods html close;
ods listing;

Viewing Frame Files

The Results window does not display links to frame files, and in the Windows environment only the body file will automatically appear in the internal browser or your preferred Web browser.

To view the frame file that integrates the body file and the table of contents, select File

Viewing Frame Files
Open from within the internal browser or your preferred Web browser. Then open the frame file that you specified using FRAME=. In the example above, this file is frame.html, which is stored in the Records directory in the Windows environment.

The frame file, frame.html, is shown below.

Viewing Frame Files

Using the Table of Contents

The table of contents created by the CONTENTS= option contains a numbered heading for each procedure that creates output. Below each heading is a link to the output for that procedure.

On some browsers, you can select a heading to contract or expand the table of contents.

Using the Table of Contents

Using Options to Specify Links and Paths

When ODS generates HTML files for the body, contents, and frame, it also generates links between the files using the HTML filenames that you specify in the ODS HTML statement. If you specify complete pathnames, ODS uses those pathnames in the links it generates.

The ODS statement below creates a frame file that has links to c: ecords oc.html and c: ecordsdata.html, and a contents file that has links to c: ecordsdata.html.

ods html body='c:
ecordsdata.html' 
         contents='c:
ecords	oc.html' 
         frame='c:
ecordsframe.html';

A portion of the source code for the HTML file frame.html is shown below. Notice that the links have the complete pathnames specified in the file specifications for the contents and body files.

Using Options to Specify Links and Paths

These links work when you are viewing the HTML files locally, but if you wanted to place these files on a Web server so that other people could access them, then the link needs to include either the complete URL for an absolute link or the HTML filename for a relative link.

The URL= Suboption

By specifying the URL= suboption in the BODY= or CONTENTS= file specification, you can provide a URL that ODS uses in all the links that it creates to the file. You can use the URL= suboption in any ODS file specification except FRAME= (because no ODS file references the frame file).

Example: Relative URLs

In this ODS HTML statement, the URL= suboption specifies only the HTML filename. This is the most common style of linking between files because maintenance is easier and the files can be moved as long as they all remain in the same directory or storage location.

ods html body='c:
ecordsdata.html' (url='data.html')
         contents='c:
ecords	oc.html' (url='toc.html')
         frame='c:
ecordsframe.html';

The source code for frame.html has only the HTML filename as specified on the URL= suboptions for the body and contents files.

Example: Relative URLs

Example: Absolute URLs

Alternatively, in this ODS HTML statement, the URL= suboptions specify complete URLs using Hypertext Transfer Protocol (HTTP). These files can be stored in the same or different locations.

ods html body='c:
ecordsdata.html'
         (url='http://mysite.com/myreports/data.html')
         contents='c:
ecords	oc.html'
         (url='http://mysite.com/mycontents/toc.html')
         frame='c:
ecordsframe.html';

As you would expect, the source code for frame.html has the entire HTTP addresses that you specified in the URL= suboptions for the body and contents files.

Example: Absolute URLs
Example: Absolute URLs

The PATH= Option

So far, you've learned to specify the complete pathname for HTML files in the BODY=, CONTENTS=, and FRAME= specifications when you want to save HTML files to specific locations. To streamline your ODS HTML statement, you can also use the PATH= option to specify the location where you want to store your HTML output, and you can use the URL=NONE to prevent ODS from using the pathname in any links it creates in your files.

Example: PATH= Option with URL=NONE

In the program below, the PATH= option directs the files data.html, toc.html, and frame.html to the C:Records directory in the Windows operating environment. The links from the frame file to the body and contents files contain only the HTML filenames data.html and toc.html.

ods listing close;
ods html path='c:
ecords' (url=none)
         body='data.html'
         contents='toc.html'
         frame='frame.html';
proc print data=clinic.admit;
run;
proc print data=clinic.stress2;
run;
ods html close;
ods listing;

This program generates the same files and links as the previous example in which you learned to use the URL= suboption with the BODY= and CONTENTS= file specifications. However, it's a bit simpler to specify the path only once in the PATH= option and to specify URL=NONE.

Example: PATH= Option with URL=NONE

Example: PATH= Option without the URL= Suboption

In the program below, the PATH= option directs the files data.html, toc.html, and frame.html to the C:Records directory in the Windows operating environment. The links from the frame file to the body and contents files contain the complete pathname, c: ecordsdata.html and c: ecords oc.html:

ods listing close;
ods html path='c:
ecords'
         body='data.html'
         contents='toc.html'
         frame='frame.html';
proc print data=clinic.admit;
run;
proc print data=clinic.stress2;
run;
ods html close;
ods listing;

Example: PATH= Option with a Specified URL

In the program below, the PATH= option directs the files data.html, toc.html, and frame.html to the C:Records directory in the Windows operating environment. The links from the frame file to the body and contents files contain the specified URL, http://mysite.com/myreports/data.html and http://mysite.com/myreports/toc.html:

ods listing close;
ods html path='c:
ecords'(url='http://mysite.com/myreports/')
         body='data.html'
         contents='toc.html'
         frame='frame.html';
proc print data=clinic.admit;
run;
proc print data=clinic.stress2;
run;
ods html close;
ods listing;

Changing the Appearance of HTML Output

You can change the appearance of your HTML output by specifying a style in the STYLE= option in the ODS HTML statement. Some of the style definitions that are currently shipped with SAS are

  • Beige

  • Brick

  • Brown

  • D3d

  • Default

  • Minimal.

Example

In the program below, the STYLE= option applies the Brick style to the output for the PROC PRINT step:

ods listing close;
ods html body='c:
ecordsdata.html'
    style=brick;
proc print data=clinic.admit label;
     var sex age height weight actlevel;
run;
ods html close;
ods listing;

The following example shows PROC PRINT output with the Brick style applied.

Example
Example
Example

Additional Features

Customizing HTML Output

You've seen that you can use the STYLE= option to apply predefined styles to your HTML output. However, you may want to further customize your results.

ODS provides ways for you to customize HTML output using definitions for tables, columns, headers, and so forth. These definitions describe how to render the HTML output or part of the HTML output. You can create style definitions using the TEMPLATE procedure. See the online documentation for more information.

Chapter Summary

Text Summary

The Output Delivery System

The Output Delivery System (ODS) makes new report formatting options available in SAS. ODS separates your output into component parts so that the output can be sent to any ODS destination that you specify.

Opening and Closing ODS Destinations

Each ODS destination creates a different type of formatted output. By default, the Listing destination is open and SAS creates listing output. Because an open destination uses system resources, it's a good idea to close the Listing destination if you don't need to create listing output. Using ODS statements, you can create multiple output formats at once. When you have several ODS destinations open, you can close them all using the ODS _ALL_ CLOSE statement.

Creating Simple HTML Output

You use the ODS HTML statement to open the HTML destination. Use the BODY= or FILE= specification to create an HTML body file containing procedure results. You can also use the ODS HTML statement to direct the HTML output from multiple procedures to the same HTML file.

Creating HTML Output with a Table of Contents

In order to manage multiple pieces of procedure output, you can use the CONTENTS= and FRAME = options with the ODS HTML statement to create a table of contents that links to your HTML output. The table of contents contains a heading for each procedure that creates output.

Specifying a Path for Output

You can also use the PATH= option to specify the directory where you want to store your HTML output. When you use the PATH= option, you don't need to specify the complete pathname for the body, contents, or frame files. By specifying the URL=option in the file specification, you can provide a URL that ODS uses in all the links that it creates to the file.

Changing the Appearance of HTML Output

You can change the appearance of your output using the STYLE= option in the ODS HTML statement. Several predefined styles are shipped with SAS.

Additional Features

ODS provides ways for you to customize HTML output using style definitions. Definitions are created using PROC TEMPLATE and describe how to render the HTML output or part of the HTML output.

Syntax

LIBNAME libref 'SAS-data-library';

ODS LISTING CLOSE;

ODS HTML PATH=file-specification

    <(URL='Uniform-Resource-Locator' | NONE)>

    BODY=file-specification

    CONTENTS=file-specification

    FRAME=file-specification

    STYLE=style-name;

PROC PRINT DATA=SAS-data-set;

RUN;

ODS HTML CLOSE;

ODS LISTING;

Sample Program

libname clinic 'c:data98patients';
ods listing close;
ods html path='c:
ecords'(url=none)
         body='data.html'
         contents='toc.html'
         frame='frame.html'
         style=brick;
proc print data=clinic.admit label;
   var id sex age height weight actlevel;
   label actlevel='Activity Level';
run;
proc print data=clinic.stress2;
   var id resthr maxhr rechr;
run;
ods html close;
ods listing;

Points to Remember

  • An open destination uses system resources. Therefore, it's a good idea to close the Listing destination before you create HTML output and reopen the Listing destination after you close the HTML destination.

  • The ODS HTML CLOSE statement closes the HTML destination and is added after the RUN statement for the procedure.

  • If you use the CONTENTS= and FRAME= options, open the frame file from within your Web browser to view the procedure output and the table of contents.

Chapter Quiz

Select the best answer for each question. After completing the quiz, you can check your answers using the answer key in the appendix.

  1. Using ODS statements, how many types of output can you generate at once?

    1. 1 (only listing output)

    2. 2

    3. 3

    4. as many as you want

  2. If ODS is set to its default settings, what types of output are created by the code below?

    ods html file='c:myhtml.htm';
    ods pdf file='c:mypdf.pdf';
    1. HTML and PDF

    2. PDF only

    3. HTML, PDF, and listing

    4. No output is created because ODS is closed by default.

  3. What is the purpose of closing the Listing destination in the code shown below?

    ods listing close;
    ods html ... ;
    1. It conserves system resources.

    2. It simplifies your program.

    3. It makes your program compatible with other hardware platforms.

    4. It makes your program compatible with previous versions of SAS.

  4. When the code shown below is run, what will the file D:Outputody.html contain?

    ods html body='d:outputody.html';
    proc print data=work.alpha;
    run;
    proc print data=work.beta;
    run;
    ods html close;
    1. The PROC PRINT output for Work.Alpha.

    2. The PROC PRINT output for Work.Beta.

    3. The PROC PRINT output for both Work.Alpha and Work.Beta.

    4. Nothing. No output will be written to D:Outputody.html.

  5. When the code shown below is run, what file will be loaded by the links in D:Outputcontents.html?

    ods html body='d:outputody.html'
             contents='d:outputcontents.html'
             frame='d:outputframe.html';
    1. D:Outputody.html
    2. D:Outputcontents.html
    3. D:Outputframe.html
    4. There are no links from the file D:Outputcontents.html.

  6. The table of contents created by the CONTENTS= option contains a numbered heading for

    1. each procedure.

    2. each procedure that creates output.

    3. each procedure and DATA step.

    4. each HTML file created by your program.

  7. When the code shown below is run, what will the file D:Outputframe.html display?

    ods html body='d:outputody.html'
             contents='d:outputcontents.html'
             frame='d:outputframe.html';
    1. The file D:Outputcontents.html.

    2. The file D:Outputframe.html.

    3. The files D:Outputcontents.html and D:Outputody.html.

    4. It displays no other files.

  8. What is the purpose of the URL= suboptions shown below?

    ods html body='d:outputody.html' (url='body.html')
             contents='d:outputcontents.html'
             (url='contents.html')
             frame='d:outputframe.html';
    1. To create absolute link addresses for loading the files from a server.

    2. To create relative link addresses for loading the files from a server.

    3. To allow HTML files to be loaded from a local drive.

    4. To send HTML output to two locations.

  9. Which ODS HTML option was used in creating the following table?

    Chapter Quiz
    1. format=brown
    2. format='brown'
    3. style=brown
    4. style='brown'
  10. What is the purpose of the PATH= option?

    ods html path='d:output' (url=none)
             body='body.html'
             contents='contents.html'
             frame='frame.html';
    1. It creates absolute link addresses for loading HTML files from a server.

    2. It creates relative link addresses for loading HTML files from a server.

    3. It allows HTML files to be loaded from a local drive.

    4. It specifies the location of HTML file output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset