SAS Output Delivery System
SAS Output Delivery System
SAS Documentation
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2012. Getting Started with the SAS 9.3 Ouput Delivery System. Cary, NC: SAS Institute Inc. Getting Started with the SAS 9.3 Ouput Delivery System Copyright 2012, SAS Institute Inc., Cary, NC, USA All rights reserved. Produced in the United States of America. For a hardcopy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc. For a Web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication. The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted materials. Your support of others' rights is appreciated. U.S. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the U.S. government is subject to the Agreement with SAS Institute and the restrictions set forth in FAR 52.22719, Commercial Computer Software-Restricted Rights (June 1987). SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513. 1st printing, August 2012 SAS Publishing provides a complete selection of books and electronic products to help customers use SAS software to its fullest potential. For more information about our e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site at support.sas.com/publishing or call 1-800-727-3228. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.
Contents
About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v Accessibility for the SAS Output Delivery System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Recommended Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Chapter 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What Is the Output Delivery System? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Benefits of Using ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 How Does ODS Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 ODS-Specific Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Words to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Chapter 2 Learning by Example: Creating Custom Reports with ODS . . . . . . . . . . . . . . . . . . 17 About the Scenario in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Creating the Default Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Chapter 3 Creating an ODS Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 About the Task That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Creating an ODS Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Chapter 4 Selecting the Contents of Your Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Identify the Output Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Select the Output Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Chapter 5 Integrating Output with Popular Business Applications and SAS . . . . . . . . . . . . . 39 About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Creating RTF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Creating PDF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Creating Enhanced HTML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Creating Excel Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Combined Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Chapter 6 Customizing the Presentation of a Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Customized RTF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Customized PROC TABULATE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Customized PDF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Customized HTML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Customized Excel Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Combined Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Chapter 7 Next Steps: A Quick Look at Advanced Features . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Working with the TEMPLATE Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Working with ODS Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
iv Contents Advanced Features of the DOCUMENT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 ODS and the DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Audience
This book is intended for new or novice users of the SAS Output Delivery System. The documentation assumes familiarity with Base SAS programming and the SAS windowing environment. Although this familiarity is assumed, users who are not familiar will still be able to complete the tasks that are described in this book.
Syntax Components
The components of the syntax for most language elements include a keyword and arguments. For some language elements, only a keyword is necessary. For other language elements, the keyword is followed by an equal sign (=). keyword specifies the name of the SAS language element that you use when you write your program. Keyword is a literal that is usually the first word in the syntax. In a CALL routine, the first two words are keywords. In the following examples of SAS syntax, the keywords are the first words in the syntax: CHAR (string, position) CALL RANBIN (seed, n, p, x);
vi About This Book ALTER (alter-password) BEST w. REMOVE <data-set-name> In the following example, the first two words of the CALL routine are the keywords: CALL RANBIN(seed, n, p, x) The syntax of some SAS statements consists of a single keyword without arguments: DO; ... SAS code ... END; Some system options require that one of two keyword values be specified: DUPLEX | NODUPLEX argument specifies a numeric or character constant, variable, or expression. Arguments follow the keyword or an equal sign after the keyword. The arguments are used by SAS to process the language element. Arguments can be required or optional. In the syntax, optional arguments are enclosed between angle brackets. In the following example, string and position follow the keyword CHAR. These arguments are required arguments for the CHAR function: CHAR (string, position) Each argument has a value. In the following example of SAS code, the argument string has a value of 'summer', and the argument position has a value of 4:x=char('summer', 4); In the following example, string and substring are required arguments, while modifiers and startpos are optional. FIND(string, substring <,modifiers> <,startpos> Note: In most cases, example code in SAS documentation is written in lowercase with a monospace font. You can use uppercase, lowercase, or mixed case in the code that you write.
Style Conventions
The style conventions that are used in documenting SAS syntax include uppercase bold, uppercase, and italic: UPPERCASE BOLD identifies SAS keywords such as the names of functions or statements. In the following example, the keyword ERROR is written in uppercase bold: ERROR<message>; UPPERCASE identifies arguments that are literals. In the following example of the CMPMODEL= system option, the literals include BOTH, CATALOG, and XML: CMPMODEL = BOTH | CATALOG | XML italics identifies arguments or values that you supply. Items in italics represent usersupplied values that are either one of the following:
vii
nonliteral arguments In the following example of the LINK statement, the argument label is a user-supplied value and is therefore written in italics: LINK label; nonliteral values that are assigned to an argument In the following example of the FORMAT statement, the argument DEFAULT is assigned the variable default-format: FORMAT = variable-1 <, ..., variable-nformat><DEFAULT = default-format>;
Items in italics can also be the generic name for a list of arguments from which you can choose (for example, attribute-list). If more than one of an item in italics can be used, the items are expressed as item-1, ..., item-n.
Special Characters
The syntax of SAS language elements can contain the following special characters: = an equal sign identifies a value for a literal in some language elements such as system options. In the following example of the MAPS system option, the equal sign sets the value of MAPS: MAPS = location-of-maps <> angle brackets identify optional arguments. Any argument that is not enclosed in angle brackets is required. In the following example of the CAT function, at least one item is required: CAT (item-1 <, ..., item-n>) | a vertical bar indicates that you can choose one value from a group of values. Values that are separated by the vertical bar are mutually exclusive. In the following example of the CMPMODEL= system option, you can choose only one of the arguments: CMPMODEL = BOTH | CATALOG | XML ... an ellipsis indicates that the argument or group of arguments following the ellipsis can be repeated. If the ellipsis and the following argument are enclosed in angle brackets, then the argument is optional. In the following example of the CAT function, the ellipsis indicates that you can have multiple optional items: CAT (item-1 <, ..., item-n>) 'value' or value indicates that an argument enclosed in single or double quotation marks must have a value that is also enclosed in single or double quotation marks. In the following example of the FOOTNOTE statement, the argument text is enclosed in quotation marks: FOOTNOTE <n> <ods-format-options 'text' | text>;
viii About This Book ; a semicolon indicates the end of a statement or CALL routine. In the following example each statement ends with a semicolon: data namegame;
length color name $8; color = 'black'; name = 'jack'; game = trim(color) || name; run;
ix
x Accessibility for the SAS Output Delivery System Table Attibutes LONGDESC= specifies a long description of a table. ALT= specifies an alternate description of a table. The following tagsets and ODS statements create output that is 508 compliant: ODS PHTML Statement opens, manages, or closes the PHTML destination, which produces simple HTML output that uses 12 style elements and no class attributes. For more information about the ODS PHTML statement, see the ODS PHTML Statement in SAS Output Delivery System: User's Guide. ODS HTMLCSS Statement opens, manages, or closes the HTMLCSS destination, which produces HTML output with cascading style sheets (CSS). For more information about the ODS HTMLCSS statement, see the ODS HTMLCSS Statement in SAS Output Delivery System: User's Guide. ODS HTML Statement opens, manages, or closes the HTML destination, which produces HTML 4.0 output that contains embedded style sheets. For more information about the ODS HTML statement, see the ODS HTML Statement in SAS Output Delivery System: User's Guide. MSOFFICE2K Tagset produces HTML code for output generated by ODS for Microsoft Office products. For more information about the MSOFFICE2K tagset, see MSOFFICE2K in Chapter 6 of SAS Output Delivery System: User's Guide. In SAS 9.1 and later releases, all of the accessibility enhancements have been merged into the ODS HTML tagsets. No additional steps are required.
xi
Recommended Reading
Here is the recommended reading list for this title. For a complete list of SAS publications, go to http://support.sas.com/publishing/index.html. SAS Output Delivery System: User's Guide Base SAS Procedures Guide SAS Language Reference: Concepts SAS Data Set Options: Reference SAS Functions and CALL Routines: Reference SAS Statements: Reference SAS System Options: Reference Step-by-Step Programming with Base SAS Software
The recommended reading list from SAS Press includes: The Little SAS Book: A Primer, Revised Second Edition Output Delivery System: The Basics and Beyond Output Delivery System: The Basics Instant ODS: Style Templates for the SAS Output Delivery System
For a complete list of SAS publications, go to support.sas.com/bookstore. If you have questions about which titles you need, please contact a SAS Publishing Sales Representative: SAS Publishing Sales SAS Campus Drive Cary, NC 27513-2414 Phone: 1-800-727-3228 Fax: 1-919-677-8166 E-mail: [email protected] Web address: support.sas.com/bookstore
Chapter 1
Introduction
What Is the Output Delivery System? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Benefits of Using ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 How Does ODS Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Components of ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Where Does ODS Put My Output? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 The DOCUMENT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 ODS Global Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Base SAS Reporting Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 TEMPLATE Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ODS-Specific Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 The Documents Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 The Templates Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 The Template Browser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Words to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Chapter 1
Introduction
ODS provides table templates that define the structure of the output from SAS procedures and from the DATA step. You can customize the output by modifying these table templates or by creating your own. ODS enables you to choose an individual output object to be formatted in a different way. For example, PROC UNIVARIATE produces multiple output objects. You can easily create HTML output, one or more output data sets, LISTING output, or printer output from one or all of these output objects. ODS stores a link to each output object in the Results window of the SAS windowing environment. SAS output formatting is now centralized in ODS. When ODS destinations are added, they are automatically made available to the DATA step and all procedures that support ODS. ODS enables you to produce output for numerous business applications from a single source. This feature saves you time and system resources because you can produce multiple types of output with a single run of your procedure or data query. For example, you can create output formatted for Microsoft Excel, Adobe Acrobat, and Microsoft Word.
functionality is the output object. The PROC or DATA step that you run provides the data component (raw data) and the name of the table template that contains the formatting instructions. The data component and table template together form the output object. There are two types of output objects created by ODS: tabular output objects and graphical output objects. These objects can be sent to any or all ODS destinations, such as PDF, HTML, RTF, or LISTING. By default, in the SAS windowing environment for Windows and UNIX, SAS uses ODS to produce HTML output. By default, in batch mode, SAS produces LISTING output. By specifying an ODS destination, you control the type of output that SAS creates. You can use ODS to manipulate one or more output objects in many different ways. You can use the DOCUMENT procedure to select, rearrange, store, or replay output objects. You can use ODS output destinations to create output in many different formats. You can use the ODS TRACE statement to determine what output objects are available, and you can use the ODS SELECT or ODS EXCLUDE statement to select or exclude the output object from an output destination.
Output Object
HTML
MARKUP
PRINTER
RTF
ODS Destinations
HTML Output
PCL
RTF Output
ODS Outputs
Table 1.1
Chapter 1
Introduction
Table 1.2 *Diagnostic Tagsets That SAS Supports
EVENT_MAP STYLE_POPUP
NAMEDHTML TEXT_MAP
SHORT_MAP TPL_STYLE_LIST
STYLE_DISPLAY TPL_SYLE_MAP
Note: There are also preproduction tagsets. These tagsets can be found at http:// support.sas.com. They are not yet supported by SAS Technical Support.
Basic Usage
Overview
ODS is used by all SAS software. However, you can explicitly use ODS with the following: DOCUMENT Procedure ODS Global Statements Base SAS Reporting Procedures TEMPLATE Procedure
Basic Usage
store the ODS output objects in raw form Note: The output is kept in the original internal representation as a data component plus a table template.
The DOCUMENT destination has a graphical user interface (GUI), called the Documents window, for performing tasks. However, you can perform the same tasks with batch statement syntax using the DOCUMENT procedure. For complete documentation on the DOCUMENT procedure, see Chapter 8, The DOCUMENT Procedure, in SAS Output Delivery System: User's Guide.
ODS Destination (Report) Statements are statements that enable you to create output that is formatted for third-party software, such as HTML, RTF, and PDF. Or, they enable you to create output that is specific to SAS, such as an ODS document, LISTING output, or a SAS data set. You can use ODS destination statements to generate and modify reports in formats such as HTML, XML, PDF, PostScript, RTF, and Microsoft Excel. The form for an ODS destination statement is the ODS statement block, which consists of ODS statements that open and close one or more ODS destinations sandwiched around your program. Your results are sent to one or more output destinations. You can use one or more ODS destination statements, one or more PROC or DATA steps, and an ODS CLOSE statement to form an ODS statement block. An ODS block has the following form: ODS output-destination 1 <options(s)>;
Chapter 1
Introduction
ODS output-destination (n) <options(s)> <your SAS program> ODS destination close statement 1; ODS destination close statement (n) In the ODS block, output-destination is the name of a valid ODS destination and option(s) are options that are valid for that destination. Your SAS program is inserted between the beginning ODS destination statement and the ODS CLOSE statement. In the following example, the output from PROC PRINT and PROC CONTENTS is sent to the PDF and RTF destinations. The STYLE= option specifies what table template to apply to the output. By default, the PDF opens in Adobe Acrobat and the RTF opens in Microsoft Word.
options obs=10 nodate; ods pdf file="myPdf.pdf" style=Banker; ods rtf file="myRTF.rtf" style=BarrettsBlue text="RTF Output"; proc print data=sashelp.class; run; proc contents data=sashelp.class; run; ods pdf close; ods rtf close;
Output 1.1 Default PDF Output
Basic Usage
Output 1.2 PDF Output with Banker Style Applied
Output 1.3
Chapter 1
Introduction
Output 1.4 RTF Output with BarrettsBlue Style Applied
ODS destinations are organized into two categories. Destinations Formatted by SAS These destinations produce output that is controlled and interpreted by SAS, such as a SAS data set, LISTING output, or an ODS document. Destinations Formatted by a Third Party These destinations produce output that enables you to apply styles or markup languages. You can print to physical printers using page description languages. For example, you can produce output in PostScript, HTML, XML, or in a markup language that you created. The following table lists the ODS destination categories, the destinations that each category includes, and the formatted output that results from each destination.
Table 1.3 Category Destination Category Table Destinations Results
Formatted by SAS
ODS document SAS LISTING output SAS data set HTML file for online viewing Markup language tagsets
HTML MARKUP
Basic Usage
Category Destinations Results
PRINTER
Printable output in one of three different formats: PCL, PDF, or PS (PostScript) Output written in Rich Text Format for use with Microsoft Word 2000
RTF
As destinations are added to ODS, they will automatically become available to the DATA step and all procedures that support ODS.
10
Chapter 1
Introduction
Output 1.5 PROC REPORT Output with Styles Applied
For complete documentation on the styles and style attributes that you can use with PROC PRINT, PROC TABULATE, and PROC REPORT, see the Base SAS Procedures Guide.
TEMPLATE Procedure
All SAS procedures produce output objects that ODS delivers to various ODS destinations based on the default specifications for the procedure or based on your own specifications. Output objects are commonly displayed as tables, data sets, or graphs. Each output object has an associated template provided by SAS that defines its presentation format. You can use the TEMPLATE procedure to view or alter a template or to create a new template by changing the headers, formats, column order, and so on. The TEMPLATE procedure enables you to create or modify a template that you can apply to your output. You can also use the TEMPLATE procedure to navigate and manage the templates stored in template stores. ODS then uses these templates to produce formatted output. Using the TEMPLATE procedure is an advanced technique. For more information about advanced ODS techniques, see Chapter 7, Next Steps: A Quick Look at Advanced Features , on page 65. For complete documentation on the TEMPLATE procedure, see the TEMPLATE procedure in the SAS Output Delivery System: User's Guide.
ODS-Specific Windows
11
ODS-Specific Windows
Overview
There are three ODS windows that enable you to manipulate or browse your ODS output and templates. Documents Window Template Window Template Browser Window
This display shows a Documents window that contains an ODS document named Sasuser.Univ. In the display, notice that Sasuser.Univ contains several directory levels. The Exponential_x directory contains the Exp output object. When you double-click on
12
Chapter 1
Introduction
an output object such as Exp, that output object is replayed in the Results window and sent to all open destinations.
Display 1.1 Documents Window
ODS-Specific Windows
13
The hierarchal view on the left side of the Templates window lists the item stores, template stores, directories, and items. The contents of a selected store or directory are displayed on the right side of the window.
Figure 1.2 Templates Window Showing Item Stores, Template Stores, Directories, and Items
A template store is an item store that contains items that were created by the TEMPLATE procedure. Items that SAS provides are in the Sashelp.Tmplmst item store. By default, compiled templates are stored physically in the Sasuser.Templat item store. You can store items that you create in any template store where you have Write access. A template store can contain multiple levels (directories).
14
Chapter 1
Introduction
In the following display, the source code for the HTMLBlue style is shown in the Template Browser window.
Display 1.2 Templates Window and Template Browser Window
Words to Know
data components a form, similar to a SAS data set, that contains the results (numbers and characters) of a DATA step or PROC step. item store a SAS library member that consists of pieces of information that can be accessed independently. The contents of an item store are organized in a directory tree structure, which is similar to the directory structure that is used by UNIX System Services or Windows. For example, a value might be stored in and located by using a directory path (root_dir/sub_dir/value). The SAS registry, Sasuser.Templat, and Sashelp.Tmplmst are examples of item stores. template store an item store that contains items that were created by the TEMPLATE procedure. Items that SAS provides are in the Sashelp.Tmplmst item store. ODS destination a designation that ODS uses to generate a specific type of output. For example, HTML, XML, LISTING, PostScript, RTF, and SAS data set are ODS destinations. ODS document a hierarchy of output objects created by the DOCUMENT procedure. These output objects are unformatted and placed in a SAS item store.
Words to Know 15
ODS template a definition of how output should appear when it is formatted. An ODS template is stored as a compiled entry in a template store, which is also known as an item store. Common ODS template types include STATGRAPH, STYLE, CROSSTABS, TAGSET, and TABLE. output object data component that is generated by a PROC or DATA step. It can also contain a table template that provides formatting instructions for the data. table template a template that describes how to format the output for a tabular output object. A table template determines the order of table headers and footers, the order of columns, and the overall appearance of the output object. Each table template contains or references table elements.
16
Chapter 1
Introduction
17
Chapter 2
18
Chapter 2
When you create this output, you determine that there is more information than you want. Specifically, you need only the Extreme Observations, Quantiles, and Moments tables from the PROC UNIVARIATE output. In addition, you want to make the output
19
easier to read. The steps in the following chapters show you how to accomplish these tasks.
Output 2.1 Default Output
20
Chapter 2
21
Chapter 3
About the Task That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Creating an ODS Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
22
Chapter 3
ods document name=work.prddocument(write); proc tabulate data=prdsale; class region division prodtype; classlev region division prodtype; var actual; keyword all sum; keylabel all='Total'; table (region all)*(division all), (prodtype all)*(actual*f=dollar10.) / misstext=[label='Missing'] box=[label='Region by Division and Type']; title 'Actual Product Sales'; title2 '(millions of dollars)'; run; proc univariate data=prdsale; by Country; var actual; run; title 'Sales Figures for First Quarter by Product'; proc sgpanel data=prdsale; where quarter=1; panelby product / novarname; vbar region / response=predict; vline region / response=actual lineattrs=GraphFit; colaxis fitpolicy=thin; rowaxis label='Sales'; run; ods document close;
Display 3.1 Documents Window
23
24
Chapter 3
25
Chapter 4
About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Identify the Output Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Using the ODS TRACE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Using the Documents Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Select the Output Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Using ODS Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Using the Documents Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Comparing the Two Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
There are two steps to select or exclude an output object. First, you must identify the name, label, or path of the output object. Second, you must use ODS to select or exclude the output object.
26
Chapter 4
UNIVARIATE step. Place the ODS TRACE OFF statement after the PROC UNIVARIATE step to stop the generation of trace information.
ods trace on; proc univariate data=prdsale; by Country; var actual; run; ods trace off;
Display 4.1 Trace Output Viewed in the SAS Log
27
28
Chapter 4
In the figure below, you can see that the labels of the output objects in the trace output correspond to the names given to the output objects in the Documents window.
Display 4.3 Comparing the Documents Window and the Trace Output
29
You can use the ODS EXCLUDE statement instead of the ODS SELECT statement. The following ODS EXCLUDE statement gives you the same results:
ods exclude BasicMeasures TestsForLocation;
30
Chapter 4
To create a new ODS document, right-click the Documents folder at the top of the Documents window, and then select New Document.
Display 4.4 Creating a New ODS Document
31
In the New Document window, select a library in which to store the new document, and enter a name for the document. Click OK.
Display 4.5 Naming a New ODS Document
32
Chapter 4
Because you selected the library Sasuser, your document is stored permanently.
Display 4.6 New Empty Document PrdCustomContent
33
When you create a new document, it is empty. You can load output into the new document by using the Documents window in two ways. You can copy and paste output from the original document (Work.PrdDocument) into the new document (Sasuser.Prdcustomcontent). Or, you can drag and drop output into the new document. You can load individual output objects one by one, as is shown below, or you can add all of the output at once. Then, you can rearrange the output. In the output below under Sasuser.Prdcustomcontent, PROC SGPANEL output is before PROC TABULATE and PROC UNIVARIATE output. Note that you can use PROC DOCUMENT statements to accomplish all these tasks without using the Documents window. For complete documentation on the DOCUMENT procedure, see the Chapter 8, The DOCUMENT Procedure, in SAS Output Delivery System: User's Guide.
Figure 4.1 Adding Output to the Sasuser.Prdcustomcontent Document
34
Chapter 4
Next, drag and drop the UNIVARIATE procedure output from Work.Prddocument into Sasuser.Prdcustomcontent. All of the output objects that PROC UNIVARIATE creates are copied into the new document.
Figure 4.2 Adding the UNIVARIATE Procedure Output
35
All output objects are in the new document. Delete the PROC UNIVARIATE output objects Basic Measures of Location and Variability and Tests For Location. Right-click on an object, and select Delete.
Display 4.7 Delete Output Objects
36
Chapter 4
Sasuser.Prdcustomcontent now contains all of the output from PROC SGPANEL and PROC TABULATE. The UNIVARIATE output now consists of only the Moments, Quantiles, and Extreme Observations tables for Canada, Germany, and the United States.
Display 4.8 Completed New Document
37
Now that you have the output that you want in the new document, you can re-create the output with only the data that you want shown. Right-click Sasuser.Prdcustomcontent, and select Replay. This will display your output to any open destinations without rerunning the procedures.
Display 4.9 Replay the New Document
38
Chapter 4
39
Chapter 5
About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Creating RTF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Creating PDF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Creating Enhanced HTML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Creating Excel Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Combined Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
40
Chapter 5
destination, your output is stored in your local directory, unless you specify a different directory with the PATH= option. After you run your program, your HTML, PDF, and Excel output opens in the Results Viewer. RTF output opens in Microsoft Word.
41
42
Chapter 5
43
44
Chapter 5
Combined Program
45
Combined Program
Now that you have created output for the various applications that you want to use, you can combine the different programs into a single program. You can create an ODS document to store your output objects. You can then replay your output or modify your output objects without having to resubmit any procedures.
CAUTION:
The following program contains numbered callouts that help explain specific parts of the program. When you copy and paste this program into a SAS code editor, the callouts are copied as well, which results in errors. If you want to copy and paste this program, use Example Code 5.2 on page 47.
Example Code 5.1 Combined Program with Callouts
options nodate nonumber; proc sort data=sashelp.prdsale out=prdsale; by Country; run; 1 ods document name=work.prddocument(write);
46
Chapter 5
body='html-bodyPrdsale.htm' contents='html-contentsPrdsale.htm' frame='html-framePrdsale.htm'; 3 ods pdf file='your-file-path/PDFPrdsale.pdf' ; 4 ods rtf file='your-file-path/RTFPrdsale.rtf' ; title 'Actual Product Sales'; title2 '(millions of dollars)'; proc tabulate data=prdsale; class region division prodtype; classlev region division prodtype; var actual; keyword all sum; keylabel all='Total'; table (region all)*(division all), (prodtype all)*(actual*f=dollar10.) / misstext=[label='Missing'] box=[label='Region by Division and Type']; run; title; title2; 5 ods rtf exclude all; 6 ods select ExtremeObs Quantiles Moments; proc univariate data=prdsale; by Country; var actual; run;
7 ods rtf select all; 8 ods pdf select none;
title 'Sales Figures for First Quarter by Product'; proc sgpanel data=prdsale; where quarter=1; panelby product / novarname; vbar region / response=predict; vline region / response=actual lineattrs=GraphFit; colaxis fitpolicy=thin; rowaxis label='Sales'; run;
9 ods exclude PRINT; 10 ods tagsets.excelxp file=your-file-path.'Prdsale.xls'; 11 ods tagsets.excelxp select PRINT; proc print data=sashelp.prdsale; run; 12 ods _all_ close; 13 ods html;
The ODS DOCUMENT statement creates the document Work.PrdDocument. Work.PrdDocument stores all of the output generated between the opening ODS DOCUMENT statement and the ODS _ALL_ CLOSE statement.
Combined Program
47
2 3
The ODS HTML statement specifies the names and paths for the body, contents, and frame files. The ODS PDF statement with the FILE= option opens the ODS PDF destination (which is a member of the PRINTER family of destinations). It specifies the name and path for the PDF output file. The ODS RTF statement with the FILE= option opens the ODS RTF destination. It specifies the name and path for the RTF output file. The ODS RTF statement with the EXCLUDE ALL option excludes all of the output objects from the following PROC UNIVARIATE output. The ODS SELECT statement specifies that the output objects ExtremeObs, Quantiles, and Moments be sent to all open destinations that do not specifically exclude PROC UNIVARIATE output with the EXCLUDE option, such as the previous ODS RTF statement. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement. The ODS RTF statement with the SELECT ALL option selects all of the output objects from the following PROC SGPANEL output. It sends the output objects to the ODS RTF destination. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement. The ODS PDF statement with the SELECT NONE option selects none of the output objects from the following PROC SGPANEL output. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement. The ODS EXCLUDE statement excludes the output object named Print from all open destinations that do not specifically select the Print output object with the SELECT option. TAGSETS.EXCELXP destination (which is a member of the MARKUP family of destinations). It specifies the name and path for the XLS output file. You can use the .XML extension instead of the EXCELXP extension. Beginning in Excel 2007, using the XLS extension will invoke a dialog box because of the new security feature that matches the content with the extension.
4 5 6
10 The ODS TAGSETS.EXCELXP statement with the FILE= option opens the
11 The ODS TAGSETS.EXCELXP statement with the SELECT option selects the
statement is useful when you have multiple destinations open at the same time.
13 Because the ODS _ALL_ CLOSE statement closes all open destinations, it is a good
practice to open the ODS HTML destination again at the end of your program. If all of the destinations are closed, you get the following warning in the SAS Log: WARNING: No output destinations active.
Example Code 5.2 Combined Program without Callouts
options nodate nonumber; proc sort data=sashelp.prdsale out=prdsale; by Country; run; ods document name=work.prddocument(write); ods html path='your-directory-path' body='html-bodyPrdsale.htm' contents='html-contentsPrdsale.htm' frame='html-framePrdsale.htm';
48
Chapter 5
49
Chapter 6
About the Tasks That You Will Perform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Customized RTF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Customized PROC TABULATE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Customized PDF Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Customized HTML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Customized Excel Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Combined Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
50
Chapter 6
By default (for DMS), ODS uses the HTMLBlue style for HTML output, the RTF style for RTF output, and the default Printer style for PDF output. The default style for each ODS destination can be viewed in the SAS Registry Editor. For the following examples, the Science style is used to ensure that the look of the presentation is consistent. To view the source of the Science style in the Template Browser window, do one of the following: Double-click the Science style. Right-click Science, and then select Open.
Display 6.1 Source of Science Style Viewed in the Template Browser Window
You can customize specific areas of some procedure output by specifying the STYLE= option in specific procedure statements. With the STYLE= option, you can change the attributes of cells. Changes include aligning text, adding URLs, changing rules, and changing the size, width, and color of a font. The STYLE= option is specified in slightly different ways for individual procedure statements. However, the general form of the STYLE= option for a procedure statement is: STYLE=<style-attribute-name=style-attribute-value> The procedures that allow direct style control are PROC PRINT, PROC REPORT, and PROC TABULATE. For documentation on these procedures, see the Base SAS Procedures Guide.
52
Chapter 6
Even though you did not specify the STYLE= option in the PROC SGPANEL statement, the style=Science option in the ODS RTF statement applies the style for PROC SGPANEL, too.
Output 6.2 Customized RTF Output Viewed in Microsoft Word
53
proc tabulate data=prdsale 1 style=[fontweight=bold]; class region division prodtype / 2 style=[textalign=center]; classlev region division prodtype / 3 style=[textalign=left]; var actual / 4 style=[fontsize=3]; keyword all sum; keylabel all='Total'; table (region all)*(division all* 5 [style=[backgroundcolor=yellow]]), (prodtype all)*(actual*f=dollar10.) / style=[bordercolor=blue] box=[label='Region by Division and Type' 6 style=[fontstyle=italic]]; run; title2; title; proc sgpanel data=prdsale; where quarter=1; panelby product / novarname; vbar region / response=predict; vline region / response=actual lineattrs=GraphFit; colaxis fitpolicy=thin; rowaxis label='Sales'; run; ods rtf close;
1 2 3 4 5 6
The STYLE= option specified in the PROC TABULATE statement changes all of the font to bold for all of the data cells. The STYLE= option specified in the CLASS statement centers the CLASS variable name headings. The STYLE= option specified in the CLASSLEV statement left-justifies the CLASS variable level value headings. The STYLE= option specified in the VAR statement changes the font size of analysis variable name headings to 3. The first STYLE= option specified in the TABLE statement changes the background color of the cells containing the sum totals of REGION and DIVISION to yellow. The second STYLE= option specified in the TABLE statement italicizes the font of the label of the empty box above the row titles.
54
Chapter 6
Because the STYLE= option is specified in the ODS RTF statement, PROC TABULATE output uses the Science style and the specific style overrides specified in individual statements.
Output 6.3 Customized PROC TABULATE Output Viewed in Microsoft Word
55
proc tabulate data=prdsale style=[fontweight=bold]; class region division prodtype / style=[textalign=center]; classlev region division prodtype / style=[textalign=left]; var actual / style=[fontsize=3]; keyword all sum; keylabel all='Total'; table (region all)*(division all*[style=[backgroundcolor=yellow]]), (prodtype all)*(actual*f=dollar10.) / style=[bordercolor=blue] style=[fontstyle=italic]]; run; title; title2; proc univariate data=prdsale; by Country; var actual; run; ods pdf close;
Output 6.4 Customized Table of Contents Created and Viewed in Adobe Acrobat
56
Chapter 6
57
58
Chapter 6
statement suboptions to the SAS log file. All tagsets have instream help. For more information about the DOC= suboption, see the ODS Tagset statement in Chapter 6, Dictionary of ODS Language Statements, in SAS Output Delivery System: User's Guide.
ods tagsets.excelxp file='your-file-path/Prdsale.xls' style=Science options (doc="help"); proc print data=sashelp.prdsale; run; ods tagsets.excelxp close;
Output 6.7 Customized Excel Output
Combined Program
Display 6.2 Help for the EXCELXP Tagset
59
Combined Program
Now that you have created output for the various applications that you want to use, you can combine the different programs into a single program. You can create an ODS document to store your output objects. You can then replay your output or modify your output objects without having to resubmit any procedures.
CAUTION:
The following program contains numbered callouts that help explain specific parts of the program. When you copy and paste this program into a SAS code editor, the callouts are copied as well, which results in errors. If you want to copy and paste this program, use Example Code 6.2 on page 62.
Example Code 6.1 Combined Program with Callouts
proc sort data=sashelp.prdsale out=prdsale; by Country; run; options nodate nonumber; 1 ods document name=work.prddocument(write);
2 ods html path='your-directory-path' body='bodyPrdsale.htm'
60
Chapter 6
proc tabulate data=prdsale 5 style=[fontweight=bold]; class region division prodtype / 6 style=[textalign=center]; classlev region division prodtype / 7 style=[textalign=left]; var actual / 8 style=[fontsize=3]; keyword all sum; keylabel all='Total'; table (region all)*(division all* 10 [style=[backgroundcolor=yellow]]), (prodtype all)*(actual*f=dollar10.) / style=[bordercolor=blue] box=[label='Region by Division and Type' 11 style=[fontstyle=italic]]; run; title; title2;
12 ods rtf exclude all; 13 ods select ExtremeObs Quantiles Moments;
title 'Sales Figures for First Quarter by Product'; proc sgpanel data=prdsale; where quarter=1; panelby product / novarname; vbar region / response=predict; vline region / response=actual lineattrs=GraphFit; colaxis fitpolicy=thin; rowaxis label='Sales'; run;
16 ods exclude PRINT; 17 ods tagsets.excelxp file=your-file-path.'Prdsale.xls' style=Science; 18 ods tagsets.excelxp select PRINT; proc print data=sashelp.prdsale; run; 19 ods _all_ close; 20 ods html;
The ODS DOCUMENT statement creates the document Work.PrdDocument. Work.PrdDocument stores all of the output generated between the opening ODS DOCUMENT statement and the ODS _ALL_ CLOSE statement. The ODS HTML statement specifies the names and paths for the body, contents, frame, and page files. The STYLE=SCIENCE option applies the Science style to all HTML output.
Combined Program
61
The ODS RTF statement with the FILE= option opens the ODS RTF destination. It specifies the name and path for the RTF output file. The STYLE=SCIENCE option applies the Science style to all RTF output. The STARTPAGE=YES option specifies to put each procedures output on a new page. The ODS PDF statement with the FILE= option opens the ODS PDF destination. It specifies the name and path for the PDF output file. The CONTENTS=YES option creates a table of contents for your PDF file. The PDFTOC=2 option specifies that the table of contents is expanded to two levels. The STYLE= option specified in the PROC TABULATE statement changes all of the font to bold. The STYLE= option specified in the CLASS statement centers the CLASS variable name headings. The STYLE= option specified in the CLASSLEV statement left-justifies the CLASS variable level value headings. The STYLE= option specified in the VAR statement changes the font size of ANALYSIS variable name headings to 3 point. The STYLE= option specified in the KEYWORD statement changes the font width of KEYWORD headings to wide. color of the cells containing the sum totals of REGION and DIVISION to yellow.
5 6 7 8 9
10 The first STYLE= option specified in the TABLE statement changes the background 11 The second STYLE= option specified in the TABLE statement italicizes the font of
Quantiles, and Moments be sent to all open destinations that do not specifically exclude PROC UNIVARIATE output with the EXCLUDE option, such as the previous ODS RTF statement. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement.
14 The ODS RTF statement with the SELECT ALL option selects all of the output
objects from the following PROC SGPANEL output. It sends the output objects to the ODS RTF destination. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement.
15 The ODS PDF statement with the SELECT NONE option selects none of the output
objects from the following PROC SGPANEL output. The ODS statement with the SELECT or EXCLUDE option must be specified after the opening ODS statement.
16 The ODS EXCLUDE statement excludes the output object named Print from all
open destinations that do not specifically select the Print output object with the SELECT option.
17 The ODS TAGSETS.EXCELXP statement with the FILE= option opens the
TAGSETS.EXCELXP destination (which is a member of the MARKUP family of destinations). It specifies the name and path for the XLS output file. You can use the .XML extension instead of the EXCELXP extension. Beginning in Excel 2007, using the XLS extension will invoke a dialog box because of a new security feature that matches the content with the extension. The STYLE=SCIENCE option applies the Science style to all TAGSETS.EXCELXP output.
18 The ODS TAGSETS.EXCELXP statement with the SELECT option selects the
62
Chapter 6
19 The ODS _ALL_ CLOSE statement closes all of the open destinations. This
statement is useful when you have multiple destinations open at the same time.
20 Because the ODS _ALL_ CLOSE statement closes all open destinations, it is a good
practice to open the ODS HTML destination again at the end of your program. If all of the destinations are closed, you get the following warning in the SAS Log: WARNING: No output destinations active.
Example Code 6.2 Combined Program without Callouts
proc sort data=sashelp.prdsale out=prdsale; by Country; run; options nodate nonumber; ods document name=work.prddocument(write); ods html path='your-directory-path' body='bodyPrdsale.htm' contents='contentsPrdsale.htm' frame='framePrdsale.htm' style=Science; ods rtf file='your-file-path/RTFPrdsaleCustom.rtf' style=Science; ods pdf file='your-file-path/PDFPrdsaleCustom.pdf' contents=yes pdftoc=2 style=Science; title 'Actual Product Sales'; title2 '(millions of dollars)'; proc tabulate data=prdsale style=[fontweight=bold]; class region division prodtype / style=[textalign=center]; classlev region division prodtype / style=[textalign=left]; var actual / style=[fontsize=3]; keyword all sum; keylabel all='Total'; table (region all)*(division all*[style=[backgroundcolor=yellow]]), (prodtype all)*(actual*f=dollar10.) / style=[bordercolor=blue] box=[label='Region by Division and Type' style=[fontstyle=italic]]; run; title; title2; ods rtf exclude all; ods select ExtremeObs Quantiles Moments; proc univariate data=prdsale; by Country; var actual; run; ods rtf select all; ods pdf select none; title 'Sales Figures for First Quarter by Product'; proc sgpanel data=prdsale; where quarter=1; panelby product / novarname; vbar region / response=predict;
63
64
Chapter 6
65
Chapter 7
Working with the TEMPLATE Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Introduction to the TEMPLATE Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 What Can You Do with the TEMPLATE Procedure? . . . . . . . . . . . . . . . . . . . . . . . 66 Working with ODS Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Advanced Features of the DOCUMENT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 74 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Working with the DOCUMENT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 ODS and the DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
ODS uses these templates to produce formatted output. You can use the TEMPLATE procedure to navigate and manage the templates stored in template stores. Here are some tasks that you can do with PROC TEMPLATE: Edit an existing template. Create links to an existing template.
66
Chapter 7
Change the location where you write new templates. Search for existing templates. View the source code of a template.
What Can You Do with the TEMPLATE Procedure? Modify a Table Template That a SAS Procedure Uses
The following output shows the use of a customized table template for the Moments output object using PROC UNIVARIATE. The program that creates the modified table template does the following: Creates and edits a copy of the default table template. Edits a header in the table template. Sets column attributes to enhance the appearance of the HTML output.
To view the code that creates the following output, see the Example 1: Editing a Table Template That a SAS Procedure Uses in Chapter 14 of SAS Output Delivery System: User's Guide.
Output 7.1 Default Moments Table
Output 7.2 Customized Moments Table (Customized HTML Output from PROC UNIVARIATE and Viewed with Microsoft Internet Explorer)
Modify a Style
When you are working with styles, you are more likely to modify a style that SAS provides than create a completely new style. The following output uses the
67
Styles.HTMLBlue template that SAS provides and includes changes made to the style to customize the outputs appearance. To view the code that creates this output, see the Example 3: Using the CLASS Statement in Chapter 13 of SAS Output Delivery System: User's Guide. In the contents file, changes to the style are to the following: The text of the header and the text that identifies the procedure that produced the output. The colors for some of the text. The font size for some of the text. The spacing in the entries in the table of contents. Two of the colors in the color list. One of these colors is used as the foreground color for the table of contents, the BY line, and column headings. The other color is used as the foreground color for many parts of the body file, including SAS titles and footnotes. The font size for titles and footnotes. The font style for headers. The presentation of the data in the table by changing attributes like cell spacing, rules, and border width.
Display 7.1
68
Chapter 7
69
The following display shows a scatterplot with an overlaid regression line and confidence limits for the mean of the HEIGHT and WEIGHT variables of a data set.
Display 7.3 Scatterplot Created with a StatGraph Template
70
Chapter 7
The following output shows the use of a customized CrossTabFreqs template for the CrossTabFreqs table. The program that creates the customized CrossTabFreqs template does the following:
Display 7.4
Modifies table regions. Customizes legend text. Modifies headers and footers. Modifies variable labels used in headers. Customizes styles for cellvalues.
71
The GTL applies accepted principles of graphics design to produce plots that are clean and uncluttered. Colors, fonts, and relative sizes of graph elements are designed for optimal impact. By default, the GTL produces PNG files, which support true color (the full 24-bit RGB color model) and enable visual effects such as anti-aliasing and transparency. A PNG file retains a small file size. GTL statement options enable you to control the content and appearance of the graphic down to the smallest detail. The GTL is designed to produce graphics with minimal syntax. The GTL uses a flexible, building-block approach to create a graph by combining statements in a StatGraph template. StatGraph templates are defined with the TEMPLATE procedure. You can create custom graphs by defining your own StatGraph templates. To create a custom graph, you must perform the following steps: 1. Define a StatGraph template with the TEMPLATE procedure. 2. Use the GTL to specify the parameters of your graph. 3. Associate your data with the template using the SGRENDER procedure. With just a few statements, you can create the graphs that you need to analyze your data. For example, you can create the following model fit plot with these statements:
proc template; define statgraph mytemplate; beginGraph; entrytitle "Model Weight by Height"; layout overlay; bandplot x=height limitupper=upper limitlower=lower; scatterplot y=weight x=height; seriesplot y=predict x=height; endlayout; endGraph; end; run; proc sgrender data=sashelp.classfit template=mytemplate; run;
72
Chapter 7
Display 7.5
The previous example defines a StatGraph template named MyTemplate, which uses values from the data set Sashelp.Classfit. This data set contains the data variables HEIGHT and WEIGHT and precomputed values for the fitted model (Y=PREDICT) and confidence band (limitupper=upper limitlower=lower). The SGRENDER procedure uses the data in Sashelp.Classfit and the MyTemplate template to render the graph. (This example is member GTLMFIT1 in the SAS Sample Library.) The following two graphics are more examples of what you can do with ODS graphics:
73
74
Chapter 7
Figure 7.2
Custom Template Rendered with PROC SGRENDER (SAS) and a Custom Style
75
With the DOCUMENT procedure, you are not limited to regenerating the same report. You can change the order in which objects are rendered, the table of contents, the templates that are used, macro variables, and ODS and system options.
76
Chapter 7
The following display shows the ODS document Work.Prddoc and its contents. To view the Documents window, submit the following command on the command line:
odsdocuments
Display 7.6 SAS Documents Window Showing Work.Prddoc Document and Documents Icon
77
The following display shows the properties of Table 1. You can see the document name and the document path, as well as other information.
Display 7.7 Table Properties for Table 1
An ODS document store is not a SAS data set, as you can see by the Document icon in the previous display. The Work.Prddoc document was written to the Work library. If it had been written to a permanent location (such as c:\temp\output), in Windows Explorer, the document store would have a file extension of SAS7BITM. After you have created a document with the ODS DOCUMENT statement, you can use the LIST statement in a PROC DOCUMENT step to view the contents of your document. The LIST statement enables you to look at the object list and folder structure in the ODS document. The following code creates a list of all levels of the Work.Prddoc document:
proc document name=work.prddoc; list / levels=all; run; quit;
The LIST statement can list what is in an entire document or in just one of the entries. For more information about the LIST statement, see Chapter 8, The DOCUMENT Procedure, in SAS Output Delivery System: User's Guide.
78
Chapter 7
In the following figure, every folder icon in the Results window corresponds to an item with a type of Dir in the LIST statement output. Every table created by a procedure corresponds to an item with a type of Table in the LIST statement output.
Figure 7.3 PROC DOCUMENT List Statement Output Compared to Results Window
To take advantage of these enhanced reporting capabilities, you can combine DATA step programming with the formatting capabilities of ODS. To create PDF output, for example, start with the DATA step tools that you are already familiar with. the DATA _NULL_ statement the FILE statement the PUT statement
Then, add a few simple ODS statements and options. You can choose from several ODS formatting statements to format the output in other presentation styles, such as HTML, RTF, and PS. For more information about ODS statements, see the Introduction to ODS Language Statements in Chapter 5 of SAS Output Delivery System: User's Guide.
79
Here are the basic steps for using ODS with the DATA step to produce reports with enhanced formatting:
Table 7.1 Steps Steps to Produce Enhanced ODS Output with the DATA Step Tools Comments
ODS formatting statements can specify formats such as listing, HTML, RTF, PS, and PDF.
You can produce output in multiple formats at the same time by specifying more than one format. Note: If you want only the default output, then you do not need a destination ODS statement.
Specify structure.
The ODS option in the FILE statement lists the variables and the order in which they appear in the output. The FILE PRINT ODS statement creates an output object by binding a data component to a table definition (template). The PUT statement writes variable values to the data component.
Additional suboptions give you even more control over the structure.
You can specify other details by using ODS suboptions in the FILE PRINT ODS statement. A simple way to output all variable values is to use PUT _ODS_.
Output data.
Use ODS statements to specify how you want ODS to format your output (for example, as HTML, RTF, or PDF). Then, in the DATA step, use the FILE PRINT ODS and PUT statements with appropriate ODS-specific suboptions to produce your report. The PUT statement writes variable values. The FILE PRINT ODS statement directs the output.1 You can use ODS to produce the output in multiple formats and to produce output at a later time in different formats without rerunning the DATA step. You control the formatting that is applied to your reports using ODS formatting statements. They open and close ODS destinations, which apply formatting to the output objects that you create with ODS and the DATA step. Here is a list of topics and sources for additional information:
Table 7.2 Topic Where to Find More Information about How to Use ODS in the DATA Step Where to learn more
Chapter 6, Dictionary of ODS Language Statements, in SAS Output Delivery System: User's Guide
If you do not specify a FILE statement, then the PUT statement writes to the SAS log, by default. If you use multiple PUT and FILE statements, then in addition to creating ODS-enhanced output, you can write to the SAS log, to the regular DATA step output buffer, or to another external file in the same DATA step.
80
Chapter 7
ODS destinations
Understanding ODS Destinations in Chapter 3 of SAS Output Delivery System: User's Guide Overview of How ODS Works in Chapter 3 of SAS Output Delivery System: User's Guide
81
Index
B
Base SAS reporting procedures 9 benefits of ODS 2 BODY= option ODS destination statements 39
C
components of ODS 2 CONTENTS= option ODS PDF statement 54 creating output combined program example 45 Excel 45 HTML 43 PDF 42 RTF 40 crosstabulation tables modifying 69 custom reports, example 17 customizing output 1, 49 combined program example 59 Excel 57 HTML 56 PDF 54 RTF 51 TABULATE procedure 52
documents See ODS documents Documents window 5, 11 compared to DOCUMENT procedure 38 opening 21 selecting output objects 29 viewing output object labels 27
E
enhanced HTML creating output 43 Excel output creating 45 customizing 57
F
features of ODS 1 FILE PRINT ODS statement 79 FILE= option ODS destination statements 39
G
global statements 5 Graph Template Language (GTL) 70 graphical output objects 2 graphics 70 GTL (Graph Template Language) 70
D
data component 14 DATA step ODS and 78 ODS reports with 79 default output, example 17 destinations See ODS destinations DOCUMENT procedure advanced features 74 capabilities 4 compared to Documents window 38
H
HTML output creating 43 customizing 56
I
identifying output objects 25
82
Index
N
NAME= option ODS DOCUMENT statement 21
O
ODS block 39 ODS destination statements 5 ODS destinations 14 categories of 8 ODS DOCUMENT CLOSE statement 21 ODS DOCUMENT statement 4, 21, 74 ODS document stores 77 ODS documents 14 creating, example 21, 75 loading output 33 ODS EXCLUDE statement 29 ODS formatting statements 79 ODS global statements 5 ODS Graphics 70 output 68 ODS HTML statement creating output 43 customizing output 56 ODS PDF statement creating output 42 customizing output 54 ODS RTF statement creating output 40 customizing output 51 ODS SELECT statement 28 ODS TAGSETS.EXCELXP statement creating output 45 customizing output 57 ODS templates 15, 65 creating with TEMPLATE procedure 10 modifying style definitions 66 modifying table templates 66 ODS TRACE statement 25 ODS windows 11 output creating default, example 17 creating Excel 45 creating HTML 43 creating PDF 42 creating RTF 40 customizing 1, 49 customizing Excel 57 customizing HTML 56 customizing PDF 54 customizing RTF 51
customizing TABULATE procedure output 52 formatting for third-party software 5 integrating with applications 39 loading into ODS document 33 location 4 ODS Graphics 68 output control statements 5 output objects 2, 15 identifying 25 selecting 28 selecting in Documents window 29 templates 10 viewing in Documents window 27
P
PATH= option ODS HTML statement 43 PDF output creating 42 customizing 54 PDFTOC= option ODS PDF statement 54 PNG files 71 PRINT procedure 9 processing for ODS 3 PUT statement 79
R
REPORT procedure 9 RTF output creating 40 customizing 51
S
SAS formatted destinations 8 SAS styles 49 selecting output objects 28 STARTPAGE= option ODS RTF statement 51 StatGraph templates 68, 71 style definitions modifying 66 STYLE= option 51 ODS HTML statement 56 ODS PDF statement 54 ODS RTF statement 51 ODS TAGSETS.EXCELXP statement 57 TABULATE procedure 52 styles provided by SAS 49
Index
83
T
table templates 15 modifying 66 tabular output objects 2 TABULATE procedure 9 customizing output 52 tagsets creating 68 list of 3 Template Browser window 13 TEMPLATE procedure 65 creating and modifying ODS templates 10 creating tagsets 68 modifying crosstabulation tables 69 modifying style definitions 66 modifying table templates 66
template stores 14 templates See ODS templates Templates window 12 opening 49 third-party formatted destinations 8
U
usage of ODS 4
W
windows for ODS 11 WRITE option ODS DOCUMENT statement 21
84
Index