Essential ODS Techniques for Creating Reports in PDF Patrick Thornton, SRI International, Menlo Park, CA

Similar documents
Using PROC REPORT to Cross-Tabulate Multiple Response Items Patrick Thornton, SRI International, Menlo Park, CA

footnote1 height=8pt j=l "(Rev. &sysdate)" j=c "{\b\ Page}{\field{\*\fldinst {\b\i PAGE}}}";

Quick Results with the Output Delivery System

Pros and Cons of Interactive SAS Mode vs. Batch Mode Irina Walsh, ClinOps, LLC, San Francisco, CA

Working the System: Our Best SAS Options Patrick Thornton, SRI International, Menlo Park, CA Iuliana Barbalau, Adecco, Pleasanton, CA

Getting Up to Speed with PROC REPORT Kimberly LeBouton, K.J.L. Computing, Rossmoor, CA

SESUG Paper RIV An Obvious Yet Helpful Guide to Developing Recurring Reports in SAS. Rachel Straney, University of Central Florida

Run your reports through that last loop to standardize the presentation attributes

Using Templates Created by the SAS/STAT Procedures

Square Peg, Square Hole Getting Tables to Fit on Slides in the ODS Destination for PowerPoint

Quality Control of Clinical Data Listings with Proc Compare

Producing Summary Tables in SAS Enterprise Guide

My Reporting Requires a Full Staff Help!

%MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System

ODS in an Instant! Bernadette H. Johnson, The Blaze Group, Inc., Raleigh, NC

Prove QC Quality Create SAS Datasets from RTF Files Honghua Chen, OCKHAM, Cary, NC

SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD

A Generalized Macro-Based Data Reporting System to Produce Both HTML and Text Files

ODS DOCUMENT, a practical example. Ruurd Bennink, OCS Consulting B.V., s-hertogenbosch, the Netherlands

Arthur L. Carpenter California Occidental Consultants, Oceanside, California

Formatting Highly Detailed Reports: Eye-Friendly, Insight-Facilitating

Advanced PROC REPORT: Getting Your Tables Connected Using Links

ODS Meets SAS/IntrNet

And Now, Presenting... Turn the Tables on Boring Reports with SAS 9.2 and RTF Tagset Options Louise S. Hadden, Abt Associates Inc.

Exporting Variable Labels as Column Headers in Excel using SAS Chaitanya Chowdagam, MaxisIT Inc., Metuchen, NJ

DESCRIPTION OF THE PROJECT

Making a SYLK file from SAS data. Another way to Excel using SAS

A Macro to Manage Table Templates Mark Mihalyo, Community Care Behavioral Health Organization, Pittsburgh, PA

Let There Be Highlights: Data-driven Cell and Row Highlights in %TAB2HTM and %DS2HTM Output

Print the Proc Report and Have It on My Desktop in the Morning! James T. Kardasis, J.T.K. & Associates, Skokie, IL

Posters. Workarounds for SASWare Ballot Items Jack Hamilton, First Health, West Sacramento, California USA. Paper

PharmaSUG Paper PO12

Tales from the Help Desk 6: Solutions to Common SAS Tasks

Using SAS Macros to Extract P-values from PROC FREQ

Uncommon Techniques for Common Variables

SAS ENTERPRISE GUIDE USER INTERFACE

TLFs: Replaying Rather than Appending William Coar, Axio Research, Seattle, WA

KEYWORDS Metadata, macro language, CALL EXECUTE, %NRSTR, %TSLIT

Combining TLFs into a Single File Deliverable William Coar, Axio Research, Seattle, WA

Introduction to SAS Procedures SAS Basics III. Susan J. Slaughter, Avocet Solutions

USING DATA TO SET MACRO PARAMETERS

Automatically Generating a Customized Table for Summarizing the Activities in Clinics

Syntax Conventions for SAS Programming Languages

SAS Graphs in Small Multiples Andrea Wainwright-Zimmerman, Capital One, Richmond, VA

ODS for PRINT, REPORT and TABULATE

The Great Escape(char) Louise S. Hadden, Abt Associates Inc., Cambridge, MA

Presentation Quality Bulleted Lists Using ODS in SAS 9.2. Karl M. Kilgore, PhD, Cetus Group, LLC, Timonium, MD

ODS/RTF Pagination Revisit

Taming a Spreadsheet Importation Monster

Beginning Tutorials. bt006 USING ODS. Ban Chuan Cheah, Westat, Rockville, MD. Abstract

PharmaSUG China Paper 059

A Way to Work with Invoice Files in SAS

Summary Table for Displaying Results of a Logistic Regression Analysis

ABSTRACT MORE THAN SYNTAX ORGANIZE YOUR WORK THE SAS ENTERPRISE GUIDE PROJECT. Paper 50-30

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

HOW TO DEVELOP A SAS/AF APPLICATION

WHAT ARE SASHELP VIEWS?

Building Sequential Programs for a Routine Task with Five SAS Techniques

Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee

Overview 14 Table Definitions and Style Definitions 16 Output Objects and Output Destinations 18 ODS References and Resources 20

ABSTRACT INTRODUCTION PROBLEM: TOO MUCH INFORMATION? math nrt scr. ID School Grade Gender Ethnicity read nrt scr

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

Hidden in plain sight: my top ten underpublicized enhancements in SAS Versions 9.2 and 9.3

IT S THE LINES PER PAGE THAT COUNTS Jonathan Squire, C2RA, Cambridge, MA Johnny Tai, Comsys, Portage, MI

Creating Macro Calls using Proc Freq

Introducing a Colorful Proc Tabulate Ben Cochran, The Bedford Group, Raleigh, NC

Paper DB2 table. For a simple read of a table, SQL and DATA step operate with similar efficiency.

Data Presentation. Paper

Using SAS Macro to Include Statistics Output in Clinical Trial Summary Table

A Macro that can Search and Replace String in your SAS Programs

PROC MEANS for Disaggregating Statistics in SAS : One Input Data Set and One Output Data Set with Everything You Need

MACROS TO REPORT MISSING DATA: AN HTML DATA COLLECTION GUIDE Patrick Thornton, University of California San Francisco

Sign of the Times: Using SAS to Produce Conference Signage Daniel K. Downing, Caremark, Scottsdale, Ariz.

Introduction to SAS Procedures SAS Basics III. Susan J. Slaughter, Avocet Solutions

Copy That! Using SAS to Create Directories and Duplicate Files

Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research

Data Quality Review for Missing Values and Outliers

Create a new document based on default template, other available template like: memo, fax, agenda.

QUERIES BY ODS BEGINNERS. Varsha C. Shah, Dept. of Biostatistics, UNC-CH, Chapel Hill, NC

Multiple Graphical and Tabular Reports on One Page, Multiple Ways to Do It Niraj J Pandya, CT, USA

Introduction. Getting Started with the Macro Facility CHAPTER 1

A Macro to Create Program Inventory for Analysis Data Reviewer s Guide Xianhua (Allen) Zeng, PAREXEL International, Shanghai, China

Get into the Groove with %SYSFUNC: Generalizing SAS Macros with Conditionally Executed Code

An Easy Route to a Missing Data Report with ODS+PROC FREQ+A Data Step Mike Zdeb, FSL, University at Albany School of Public Health, Rensselaer, NY

One SAS To Rule Them All

Cleaning Duplicate Observations on a Chessboard of Missing Values Mayrita Vitvitska, ClinOps, LLC, San Francisco, CA

SAS Studio: A New Way to Program in SAS

Table 1 in Scientific Manuscripts; Using PROC REPORT and the ODS System Carter Sevick, DoD Center for Deployment Health Research, San Diego, CA

Tips and Tricks for Creating Multi-Sheet Microsoft Excel Workbooks the Easy Way with SAS. Vincent DelGobbo, SAS Institute Inc.

So Much Data, So Little Time: Splitting Datasets For More Efficient Run Times and Meeting FDA Submission Guidelines

An Introduction to ODS Tagsets

Version 8 ODS (Output Delivery System)

Paper HOW-06. Tricia Aanderud, And Data Inc, Raleigh, NC

The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China

PDF Multi-Level Bookmarks via SAS

Statistics, Data Analysis & Econometrics

Correcting for natural time lag bias in non-participants in pre-post intervention evaluation studies

A Quick and Gentle Introduction to PROC SQL

Sending Text Messages from SAS

Transcription:

Thornton, S. P. (2006). Essential ODS techniques for creating reports in PDF. Paper presented at the Fourteenth Annual Western Users of the SAS Software Conference, Irvine, CA. Essential ODS Techniques for Creating Reports in PDF Patrick Thornton, SRI International, Menlo Park, CA ABSTRACT This paper lists and briefly describes ODS techniques that I have found most useful in capturing SAS 9.1 results and creating user friendly PDF reports on a Windows operating system. The techniques are presented for the beginning SAS user with examples and references to more detailed papers. The ODS techniques include capturing one-way frequency output to a set, creating a PDF document, changing styles, controlling page setup (e.g. orientation, date, title, and footnote), using PUT, and formatting and traffic-lighting PROC REPORT. INTRODUCTION The purpose of this paper is to list and briefly describe the most important techniques I have used while creating stakeholderfriendly PDF reports. Table 1 provides an overview where the purpose for each row s example is stated in column 1, the technique described in column 2, an example in column3 and the result in the remaining column. TABLE 1. OVERVIEW OF ESSENTIAL ODS TECHNIQUES Purpose ODS Technique Example Example Result Determine available through ODS Using ODS send object information to the LOG by specifying TRACE ON. ods trace on; proc freq =my; tables _all_; ods trace off; The name, label, template and path were displayed for each object. The name ONEWAYFREQS was determined. Obtaining Creating a PDF Customizing headers and footers Changing the look of the overall PDF Creating a page of custom formatted text Customizing PDF Bookmarks Using ODS OUTPUT specify the object name and set to be created. objectname=set Using ODS PDF specify the full path of a PDF. file=full_path Specify style attributes and values before the quoted text in a TITLE or FOOTNOTE. attribute=style_value Using ODS PDF, specify the style to use style=stylename Using ODS specify a character (.i.e. ^) that will be used by ODS to recognize style information in PUT statements. escapechar= character Using ODS to change the default SAS PDF bookmarks. proclabel contents= ods output onewayfreqs=freqs; proc freq =my; tables _all_; ods output close; ods pdf file= c:\freqs.pdf ; proc print =freqs; Options nodate; Title1 j=left font=courier bold Frequencies ; Footnote1 height=8pt j=right "&sysdate"; ods pdf file= c:\freqs.pdf style=sasdocprinter; proc print =freqs; ods pdf file= c:\freqs.pdf ; ods escapechar='^'; _null_; file print; put "^S={font_size=4}" 'Table of Contents'; proc print =freqs; ods pdf file= c:\freqs.pdf ; ods proclabel Report 1 ; proc print =freqs contents= Frequencies ; 1 Data set FREQS was created with the count and percent for all variables from the set MYDATA. FREQS.PDF contains the standard formatted output from PROC PRINT. Option NODATE removed the standard date and time. The PDF displayed a left justified, courier, bold header, and a date as a small right footer. PDF output contains the PROC PRINT output formatted using the built-in style SASDOCPRINTER. A page was created with the title Table of Contents prior to a page of PROC PRINT output. Additional PUT statements may be used to create a table of contents Change the default PDF bookmarks created by PROC PRINT. The label The Print Procedure was changed to Report 1 and Data Set Freqs changed to Frequencies. Together the previous ODS techniques may be used to create dramatic changes in the standard SAS output to PDF. Later sections of this paper describe these ODS techniques in more detail and list some essential ODS techniques for PROC REPORT.

USING ODS TO CREATE AN OUTPUT DATA SET As shown in Table 1, I created a set called FREQS using ODS OUTPUT ONEWAYFREQS=FREQS. I determined the name ONEWAYFREQS by using ODS TRACE ON. I preferred a different structure for FREQS, so I used the macro GETFREQ (included in the last section) to run the FREQ procedure, create the set FREQS using ODS, and restructure the set. The macro GETFREQ only requires a library name and set name as parameters. Specifying a variable list is optional. %let root = C:\projects\PDF\; libname mylib "&root"; %getfreq(mylib,my,list=); CREATING A PDF DOCUMENT Combining many of the techniques shown in Table 1, the following syntax creates a PDF document with a first page having the title table of contents and a second page of listing using SASDOCPRINTER style: Options nodate nocenter; ods pdf file= &root.pdfpaper1_2.pdf style=sasdocprinter; ods escapechar='^'; ods proclabel Table of Contents ; _null_; file print; put "^S={font_size=4}" 'Table of Contents'; Title1 j=left font=courier bold Report 1: Enrollment ; Footnote1 height=8pt j=right "&sysdate"; ods proclabel Report 1: Enrollment ; proc print =freqs noobs label contents= Frequencies ; var tablename varname varvalue frequency percent; The ODS techniques I have shown were discussed in more detail in several papers, so I encourage you to review the titles listed in the references and recommended reading sections. The following section highlights some of the issues and papers I found most valuable in learning these techniques. SAS STYLES AND CUSTOM STYLES There are many valuable papers on SAS styles and their creation or modification using the TEMPLATE procedure. Cartier (2002) and Delaney (2003) both showed how the SAS Explorer frame can be used to view the TEMPLATES environment by clicking on the results tab, VIEW menu, and TEMPLATES option. Within the TEMPLATES environment, the built-in SAS styles may be viewed by clicking the SASHELP.TMPLMST folder and the STYLES subfolder. The SASDOCPRINTER style I used in the previous examples is on the list, as well as many others. You may also use the following syntax to print a list of available styles: ods output stats=stylesout; proc template; list styles; ods output close; proc print =stylesout; While this paper used a built-in SAS style, it is possible to modify templates and create custom styles (Cartier, 2002; Delaney, 2003; Gupta, 2001; McNeil, 2001; Rath, 2002). Delaney (2003) used PROC TEMPLATE to label PDF secondary bookmarks. He pointed out that the PRINT, REPORT, TABULATE, and FREQ for multi-way tables were the only procedures that have the CONTENTS option necessary to rename secondary bookmarks, so he demonstrated a technique for labeling secondary bookmarks using a modified template. McNeill (2001) and Bessler (2005) were also good references for the use of style attributes and values in TITLE, FOOTNOTE, and PUT statements, as well as procedures. If you are interested in understanding how templates, styles and the other techniques in this paper fit into the overall SAS ODS picture, I recommend Gupta (2001). ODS AND PROC REPORT This section covers some techniques to further enhance the ODS output you can obtain by using PROC REPORT. You will not learn how to use the REPORT procedure in this section, but if you do not already know PROC REPORT these powerful ODS techniques will hopefully inspire you to learn. I ll cover two types of techniques: (a) using the STYLE option to PROC REPORT or to a DEFINE statement and (b) using a CALL DEFINE routine within a 2

COMPUTE block to change a style. Together these two techniques seem to command a high degree of formatting flexibility for a relatively small effort to learn. Both of these techniques build on the same style form used in the previous section: STYLE = [attribute=value]. The first row of Table 2 shows syntax used to change the background color of a report to light blue. In this context the style option requires a parameter that identifies the aspect of the report to change, thus specifying REPORT in parentheses applies the style change to the whole report. Other aspects of the report you can specify include HEADER, COLUMN, LINES, or SUMMARY. The style attributes you specify will vary depending on the aspect of the report you are trying to change. A SAS procedures guide covering PROC REPORT is a good source to determine available style attributes and values (see SAS Institute Inc, 1999). The following website also lists SAS style attributes and values that may be used with SAS procedures TABULATE and REPORT. http://v8doc.sas.com/sashtml/proc/z0060410.htm#z0591394 TABLE 2. ESSENTIAL ODS TECHNIQUES FOR PROC REPORT Purpose Technique Example Syntax Customize Use PROC REPORT STYLE proc report the overall option and REPORT parameter to style(report)=[background=lightblue]; report. change the default style. Customize a line of text to appear before the body of the report Color a column of Color a row based on the values of the Color a specific cell based on its value style(report)=[attribute=value] Use PROC REPORT STYLE option and LINES parameter to change the default style. style(lines)=[attribute=value] Use the DEFINE statement STYLE option. style =[attribute=value] Use the CALL DEFINE routine in a COMPUTE block to change a default style for a row based on the value of the. Use Proc FORMAT to create a format where a color is specified. Use the DEFINE statement STYLE option to set background equal to the format. proc report style(lines)=[font_size=6]; compute before _page_ / left; Line @1 'Action: Check unexpected values shown in red'; define var/ display style=[background=red]; define t /computed noprint; compute t; t = order; if t = 1 then call define(_row_,"style","style={background= cornflowerblue}"); proc format; value $uxv '999'='red' '988' = 'red'; define varvalue / display style=[background=$uxv.]; The second row of Table 2 demonstrates the use of STYLE to customize LINE statements throughout the report. In the example, the text Action: Check unexpected values shown in red is changed to font size 6 and positioned left justified just above the body of the report. The third row demonstrates STYLE as an option to a DEFINE statement. The DEFINE statement is usually used to identify a variable appearing as a column in the REPORT procedure, thus by specifying style=[background=red] the column of values in the report is colored red. The fourth row in Table 2 shows how ODS and the REPORT procedure allow the style of a row to be set based on the values of a variable in the procedure. In set FREQS the variable ORDER is equal to 1 at the beginning of each logical block of observations, so the syntax sets the computed variable T equal to ORDER and then tests for the value of T. When T = 1 the current row s background style is set to the color cornflowerblue which is just a bit darker than the blue background for the whole table. The fifth row of Table 2 shows how a format may be assigned to a STYLE background attribute so that only cells of a certain value are given a certain background color. 3

The following syntax combines many of the previous techniques and produced the output in Figure 1. %let root = C:\projects\PDF\; libname rslib "&root"; %let lib = rslib; options nodate nonumber nocenter orientation=landscape; footnote1 height=8pt j=right "&sysdate"; Title1 j=center font=courier bold height=8 'Report 1: Frequencies of Student Enrollment Variables'; ods pdf file="&root.pdfpaper1_2.pdf" style=sasdocprinter; Proc report =&lib..freqs nowd style(report)=[background=lightblue just=c] style(lines)=[font_size=6]; columns set varname order varvalue frequency percent t; define set/ group noprint; define varname /group display; define order /order display noprint; define varvalue / display style=[background=$uxv.]; define frequency / display; define percent / display; define t /computed noprint; compute t; t = order; if t = 1 then call define(_row_,"style","style={background=cornflowerblue}"); compute before _page_ / left; Line @1 'Action: Check unexpected values shown in red'; FIGURE 1: PROC REPORT OUTPUT WITH ODS FORMATTING 4

MACRO GETFREQ %macro getfreq(lib,din,list=_all_); ods listing close; ods output onewayfreqs=temp; proc freq =&din; tables &list / missprint; format _all_; ods output close; ods listing; proc sort =temp nodupkey out=list; by table; _null_; set list; call symput("v" trim(left(_n_)),trim(left(scan(table,2)))); call symput("vc",trim(left(_n_))); proc sort =temp; by table; temp2(keep= set varname varvalue frequency percent order); set temp; by table; retain order 0; length set $30. varname $25. varvalue $35. frequency percent order 8. ; set = "&din"; label set = "Data Set" varname="variable Name" varvalue="variable Value" frequency = "Frequency" percent="percent" order="value Order"; if first.table then order = 1; else order=order+1; varname = scan(upcase(table),2); %do i = 1 %to &vc; %let varname=%upcase(&&v&i); %if &i = 1 %then %do; if varname =upcase("&varname") then varvalue = trim(left(f_&varname)); %else %do; else if varname =upcase("&varname") then varvalue = trim(left(f_&varname)); %let trackd=; %let trackd = %sysfunc(exist(&lib..freqs)); %if &trackd > 0 %then %do; &lib..freqs; set &lib..freqs temp2; %else %do; &lib..freqs; set temp2; proc delete =list temp temp2; %mend; 5

CONCLUSION The ODS techniques in this paper included capturing one-way frequency output to a set, creating a PDF document, changing styles, controlling page setup (e.g. orientation, date, title, and footnote), using PUT, and formatting and traffic-lighting PROC REPORT. REFERENCES Bessler, L. (2005). Getting started with, and getting the most out of, SAS ODS PDF: No mastery of PROC TEMPLATE required. SAS Conference Proceedings: Technical Solutions, Phuse, Heidelberg, Germany. Cartier, J. (2002). Visual styles for V9 SAS output. SAS Conference Proceedings: Technical Solutions,. SUGI 27, Delaney, K.P. (2003) ODS PDF: It s not just for printing anymore. SAS Conference Proceedings: Data Presentation Section, SUGI 28, Seattle, Washington, US. Gupta, S. K. (2001). Using styles and templates to customize SAS ODS output. SAS Conference Proceedings: Advanced Tutorials, SUGI 26, Seattle, Washington, US. McNeill, S. (2001) Changes and Enhancements for ODS by Example (through version 8.2). SAS Conference Proceedings: Advanced Tutorials, SUGI 26, Long Beach, California, US. Rath, V. (2002). How to change the template and table of contents for SAS web applications. Washington DC, SAS Users Group 2002 First Quarter Meeting (http://dc-sug.org/pastprog.html). RECOMMENDED READING SAS Institute Inc. (1999). The complete guide to the SAS Output Delivery System, Version 8. Cary, NC: SAS Institute Inc. SAS Institute Inc. (1999). SAS Procedures Guide, Version 8. Cary, NC: SAS Institute Inc. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: S. Patrick Thornton Ph.D., Sr. Social Science Programmer SRI International, Center for Education and Human Services Phone: 650 859-5583 Fax: 650 859-2861 Email: patrick.thornton@sri.com Web: www.sri.com 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 trademarks of their respective companies. 6