3.3. Formatting Output with the Output Delivery System

The SAS System provides users with a familiar and automatic way to look at output in a listing file. Although easy to use, it is not extremely flexible when it comes to creating “nice” looking output. The SAS Output Delivery System (ODS) provides many ways to format output by controlling the way it is accessed and formatted. Many output formats are available with ODS, including traditional SAS monospace font (that is, listing).

ODS was first introduced in Version 7 as a way to improve the appearance of traditional SAS output. It enables “quality” looking output to be produced without the need to import it into word processors such as MS-Word and WordPerfect. Since then, many new output formatting features and options have been made available for SAS users. With ODS, users have a powerful and easy way to create and access formatted procedure and DATA step output.

3.3.1. ODS and Output Formats

ODS statements are classified as global statements and are processed immediately by the SAS System. With built-in format engines, referred to as output destinations, ODS prepares output using special formats and layouts. The diagram below illustrates the types of output that can be produced with ODS.

ODS Output Destinations

PROC and DATA steps produce output in the form of an output object to any and all open destinations. An output destination controls what format engine is turned on during a step or until you specify another ODS statement. One or more output destinations can be opened concurrently. When a destination is open, one or more output objects can be sent to it. Conversely, when closed, output objects are not sent to the destination.

Several good ODS books are available for further study on this exciting facility including The Complete Guide to the SAS Output Delivery System, Version 8; Output Delivery System: The Basics by Lauren E. Haworth; and Quick Results with the Output Delivery System by Sunil Kumar Gupta.

3.3.2. Sending Output to a SAS Data Set

Output produced by the SQL procedure can also be used as input to another vendor’s SQL, procedure, or DATA step. ODS provides an easy and consistent alternative for creating a SAS table of results. For users already familiar with ODS, this approach will consist of specifying the OUTPUT destination in an ODS statement. For users preferring a more traditional ANSI SQL approach, the CREATE TABLE statement (see Chapter 5, “Creating, Populating, and Deleting Tables,” for more details) will be the method of choice. An output SAS data set produced by the SQL procedure can also be used as input in another PROC SQL step, SAS procedure, or DATA step.

Although the CREATE TABLE statement is the standard method of creating a table in PROC SQL, you can also use the ODS OUTPUT statement to produce a table. The result table is then a rectangular structure consisting of one or more rows and columns. In this example, the SQL procedure’s results are stored in object SQL_Results and are then sent to data set SQL_DATA using the ODS OUTPUT destination. The resulting data set is displayed using VIEWTABLE.

SQL Code

ODS LISTING CLOSE;
ODS OUTPUT SQL_Results = SQL_DATA;
PROC SQL;
  TITLE1 'Delivering Output to a Data Set';
  SELECT prodname, prodtype, prodcost, prodnum
    FROM PRODUCTS
      ORDER BY prodtype;
QUIT;
ODS OUTPUT CLOSE;
ODS LISTING;

Results

3.3.3. Converting Output to Rich Text Format

Rich Text Format (RTF) is text that includes codes that represent special formatting attributes. Although most frequently associated with a word processing program’s ability to read and create encapsulated text fonts and highlighting attributes during copy-and-paste operations, the ODS RTF destination permits output generated by SAS to be packaged as rich text format. This enables you to produce output that can be shared.

The next example illustrates SQL output being sent to an external RTF file using the RTF format engine. First, the default Listing destination is closed, and then the RTF format engine is opened with an external file destination to which SQL results will be routed. Once the SQL procedure executes, the RTF destination is closed and the default Listing destination is opened.

Note:Opening the RTF file automatically invokes your system’s default word processor and displays the file contents.

SQL Code

ODS LISTING CLOSE;
ODS RTF FILE='c:SQL_Results.rtf';
PROC SQL;
  TITLE1 'Delivering Output to Rich Text Format';
  SELECT prodname, prodtype, prodcost, prodnum
    FROM PRODUCTS
      ORDER BY prodtype;
QUIT;
ODS RTF CLOSE;
ODS LISTING;

Results

3.3.4. Delivering Results to the Web

With the popularity of the Internet, you may find it useful to deploy selected pieces of output on your intranet or Web site. ODS makes deploying output to the Web a snap. The HTML destination creates syntactically correct HTML code to be used with one of the leading Internet browsers.

Four types of files can be produced with the ODS HTML destination: 1) body, 2) contents, 3) page, and 4) frame. A unique file name must be assigned to each file created with the ODS HTML statement. A custom and integrated file structure is automatically created when each file is combined with a frame file. To improve navigation and access of information, the Web browser automatically places horizontal and vertical scroll bars on the generated page, if necessary.

The next example illustrates PROC SQL output being sent to external HTML files using the HTML format engine. First, the default Listing destination is closed, and then the HTML format engine is opened specifying BODY, CONTENTS, PAGE, and FRAME external files for the routing of SQL procedure results. Once the SQL procedure executes, the HTML destination is closed and the default Listing destination is opened.

SQL Code

ODS LISTING CLOSE;
ODS HTML     BODY='c:Products-body.html'
         CONTENTS='c:Products-contents.html'
             PAGE='c:Products-page.html'
            FRAME='c:Products-frame.html';
PROC SQL;
  TITLE1 'Products List';
  SELECT prodname, prodtype, prodcost, prodnum
    FROM PRODUCTS
      ORDER BY prodtype;
QUIT;
ODS HTML CLOSE;
ODS LISTING;

Results

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

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