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

Similar documents
ET01. LIBNAME libref <engine-name> <physical-file-name> <libname-options>; <SAS Code> LIBNAME libref CLEAR;

Hooking up SAS and Excel. Colin Harris Technical Director

Create Metadata Documentation using ExcelXP

Applications Big & Small. Printable Spreadsheets Made Easy: Utilizing the SAS Excel XP Tagset Rick Andrews, UnitedHealth Group, Cary, NC

ODS TAGSETS - a Powerful Reporting Method

Moving Data and Results Between SAS and Excel. Harry Droogendyk Stratia Consulting Inc.

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

Fall 2012 OASUS Questions and Answers

Reporting from Base SAS Tips & Tricks. Fareeza Khurshed BC Cancer Agency

SAS ENTERPRISE GUIDE USER INTERFACE

Exchanging data between SAS and Microsoft Excel

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

An Introduction to Creating Multi- Sheet Microsoft Excel Workbooks the Easy Way with SAS

Data Edit-checks Integration using ODS Tagset Niraj J. Pandya, Element Technologies Inc., NJ Vinodh Paida, Impressive Systems Inc.

Multi-sheet Workbooks from SAS. data using the ODS ExcelXP tagset. Another Way to EXCEL using SAS

New for SAS 9.4: A Technique for Including Text and Graphics in Your Microsoft Excel Workbooks, Part 1

It s not the Yellow Brick Road but the SAS PC FILES SERVER will take you Down the LIBNAME PATH= to Using the 64-Bit Excel Workbooks.

Paper ###-YYYY. SAS Enterprise Guide: A Revolutionary Tool! Jennifer First, Systems Seminar Consultants, Madison, WI

CDISC Variable Mapping and Control Terminology Implementation Made Easy

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

Creating AND Importing Multi-Sheet Excel Workbooks the Easy Way with SAS

Choosing the Right Tool from Your SAS and Microsoft Excel Tool Belt

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

Maintaining Formats when Exporting Data from SAS into Microsoft Excel

Using Templates Created by the SAS/STAT Procedures

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

A Practical Introduction to SAS Data Integration Studio

Taming a Spreadsheet Importation Monster

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

Creating Multi-Sheet Excel Workbooks the Easy Way with SAS Vincent DelGobbo, SAS Institute Inc., Cary, NC

Give m Their Way They ll Love it! Sarita Prasad Bedge, Family Care Inc., Portland, Oregon

Paper AD12 Using the ODS EXCEL Destination with SAS University Edition to Send Graphs to Excel

Traffic Lighting Your Multi-Sheet Microsoft Excel Workbooks the Easy Way with SAS Vincent DelGobbo, SAS Institute Inc., Cary, NC

All Aboard! Next Stop is the Destination Excel

One SAS To Rule Them All

ODS EXCEL DESTINATION ACTIONS, OPTIONS, AND SUBOPTIONS

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

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

Tips for Moving From Base SAS 9.3 to SAS Enterprise Guide 5.1 Anjan Matlapudi Corporate Medical Informatics AmeriHealth Caritas Family of Companies

PharmaSUG China 2018 Paper AD-62

Syntax Conventions for SAS Programming Languages

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

ABSTRACT INTRODUCTION THE ODS TAGSET FACILITY

Utilizing the VNAME SAS function in restructuring data files

%check_codelist: A SAS macro to check SDTM domains against controlled terminology

Essentials of the SAS Output Delivery System (ODS)

SESUG Paper AD A SAS macro replacement for Dynamic Data Exchange (DDE) for use with SAS grid

New for SAS 9.4: Including Text and Graphics in Your Microsoft Excel Workbooks, Part 2

The Perfect Marriage: The SAS Output Delivery System (ODS) and

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

Getting Started with the SAS 9.4 Output Delivery System

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

Programming Gems that are worth learning SQL for! Pamela L. Reading, Rho, Inc., Chapel Hill, NC

Moving Data and Results Between SAS and Microsoft Excel

NEW FEATURES IN FOUNDATION SAS 9.4 CYNTHIA JOHNSON CUSTOMER LOYALTY

How to Keep Multiple Formats in One Variable after Transpose Mindy Wang

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

Paper RV-011 Using the Excel XP tagset and DDE to create At-A-Glance Summary Spreadsheets Compiled, Written, and Formatted with one SAS click!

- 1 - ABSTRACT. Paper TU02

Figure 1. Table shell

Creating Stylish Multi-Sheet Microsoft Excel Workbooks the Easy Way with SAS Vincent DelGobbo, SAS Institute Inc., Cary, NC

A Methodology for Truly Dynamic Prompting in SAS Stored Processes

Using the SAS Add-In for Microsoft Office you can access the power of SAS via three key mechanisms:

Automated Checking Of Multiple Files Kathyayini Tappeta, Percept Pharma Services, Bridgewater, NJ

Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables

Presentation Goals. Now that You Have Version 8, What Do You Do? Top 8 List: Reason #8 Generation Data Sets. Top 8 List

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

Paper S Data Presentation 101: An Analyst s Perspective

SAS Visual Analytics Environment Stood Up? Check! Data Automatically Loaded and Refreshed? Not Quite

Getting Started with the SAS 9.4 Output Delivery System

Uncommon Techniques for Common Variables

Creating Your Own Worksheet Formats in exporttoxl

Moving Data and Analytical Results between SAS and Microsoft Office

Paper # Jazz it up a Little with Formats. Brian Bee, The Knowledge Warehouse Ltd

Using a Fillable PDF together with SAS for Questionnaire Data Donald Evans, US Department of the Treasury

Accessing Data and Creating Data Structures. SAS Global Certification Webinar Series

Applications Development

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

BI-09 Using Enterprise Guide Effectively Tom Miron, Systems Seminar Consultants, Madison, WI

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

Creating Zillions of Labels (and Other Documents) the Easy Way with ODS and Microsoft Word

Enterprise Client Software for the Windows Platform

Moving Data and Analytical Results between SAS and Microsoft Office

The GEOCODE Procedure and SAS Visual Analytics

DBLOAD Procedure Reference

Excel Microsoft Query User Guide Pdf 2007 Advanced Macros Quick

Real Time Clinical Trial Oversight with SAS

Configuration Configuration

An Application of ODS Tagsets. Notice! Paper

It s Proc Tabulate Jim, but not as we know it!

Quality Control of Clinical Data Listings with Proc Compare

SAS Online Training: Course contents: Agenda:

Post-Processing.LST files to get what you want

Using SAS DDE, SAS Macro and Excel VBA Macros to Create Automated Graphs for Multiple MS Excel Workbooks

Multi-Threaded Reads in SAS/Access for Relational Databases Sarah Whittier, ISO New England, Holyoke, MA

Creating a Departmental Standard SAS Enterprise Guide Template

An Efficient Tool for Clinical Data Check

SAS Standard Reporting Application For e-publication Of MS Office Documents Simon Pickles, Fidelity Investments ltd

Getting Started with the XML Engine

Getting it Done with PROC TABULATE

Transcription:

Paper 74924-2011 Exporting Variable Labels as Column Headers in Excel using SAS Chaitanya Chowdagam, MaxisIT Inc., Metuchen, NJ ABSTRACT Excel output is the desired format for most of the ad-hoc reports requested for an easy interpretation and exploration of data. However, to make these reports more informative variable labels could be used instead of variable names as column header. This is harder to achieve by the conventional SAS Export procedure, PROC EXPORT. This paper will provide easy and quick methods of exporting SAS data to multiple Excel sheets with variable labels as column headers using EXCEL Libname and ODS Markup. INTRODUCTION Excel is a universal platform for simple data analysis, sharing information and data interpretation. There are numerous ways to export data from SAS into Excel, and these procedures improve with evolving versions of SAS. Companies which still uses older versions of SAS 8.2 and older uses PROC EXPORT and DDE to do the job without any easy options of customizing the reports. Though DDE allows SAS to run VBA macros within the excel workbook and data formatting, it is not worth doing some laborious work for a simple formatted EXCEL output. Stepping to SAS 9 and later versions, SAS has come up with EXCEL Libname and ODS Markup, a middle ground between the plain data dump using PROC EXPORT and highly laborious DDE. The goal of this paper is to discuss these two methods that are available for SAS 9 and later versions, which are fairly simple to get the variable labels as column headers in EXCEL outputs. EXCEL LIBNAME Excel Libname is better than a simple PROC EXPORT & other methods available in the following ways: 1) It can be done with a simple data step and a Libname statement. 2) Variable Labels can be generated as column headers. 3) Multiple sheets can be generated dynamically in one single spread sheet. 4) Can avoid formatting issues with a smile SQL code dynamically generated if needed? GETTING STARTED Test Data Used for Demonstration data Test; attrib name length=$10 label='name of the Subject' gender length= $8 label='gender at the time of Birth'; input name $ gender $; cards; Tom Male Mary Female George Male Christine Female Jim Male Beth Female ; 1

THE BASIC EXCEL LIBNAME SYNTAX LIBNAME libref <engine-name> <physical-file-name> <libname-options>; <SAS Code> LIBNAME libref CLEAR; The code below will generate variable names as column headers using Excel LIBNAME and a simple DATA STEP with DBLABEL dataset option. Libname myxlbook 'C:\Path\Libname.xls'; *To Replace the Sheet With new data existing data must be deleted; proc datasets lib=myxlbook; delete Names Gender; quit; *Sheet-1 (Name of the sheet-names); data myxlbook.names(dblabel=yes); set test; *Sheet-2 (Name of the sheet-gender); data myxlbook.gender(dblabel=yes); set test; libname myxlbook clear; The output generated using the above code is shown is Figure1. DBLABEL=YES During output to Excel, SAS variable labels, instead of variable names, are written out to column headers by changing to the data set option DBLABEL=YES. All labels written in this way must be unique. This allows long variable labels with spaces and special characters to be written from SAS into Excel column headers (Explore more about the other dataset options). Figure 1: Output using Excel Libname engine To replace the same excel output with new data, one need to delete the existing data and rewrite file with new data (for this PROC DATASETS procedure could be used). proc datasets lib=myxlbook; delete Names Gender; quit; The above code will delete the data present in the each sheet that has to be replaced with the new data. The log will refer the deleted sheets as sheet-name$ as shown in the figure 2. 2

Figure 2: Log Generated while deleting the data in the excel work book THINGS TO REMEMBER When writing to Excel, workbook should not be open. Delete old data before rewriting the workbook. Variables in the SAS dataset will be exported in the same order. ODS TAGSETS (supported by Microsoft Excel (Version 2002 and later). Output Delivery System with Tagsets generates XML outputs; Tagsets with ExcelXP generates XML output that can be opened in Excel. ODS Tagsets is a better way to generate multiple sheets with more of customizing options. 1. No formatting issues loss and change of data during transformation of SAS datasets to Excel, since the data is preserved as xml file. 2. Customizing outputs by Adding filters to different fields lock the headers, dimensions of each cell, and adding titles footnotes in the same spreadsheet. 3. Using different layouts customizing the template using PROC TEMPLATE. 4. Create Multiple Excel Sheets. 5. Traffic lighting to pick issues and also look at the results in one glance. THE BASIC ODS TAGSETS SYNTAX ods listing close; ods tagsets.excelxp path= PATH file= file-name.xls style= style-name <Tagset options>; <SAS Code Reporting Procedures> ods tagsets.excelxp close; ods listing; Using the test data, the code below generates Excel output shown in figure3, Generally any reporting procedure like PROC PRINT, PROC REPORT, PROC TABULATE can be used in ODS tagsets. But to get the variable labels as column headers PROC PRINT with split option will generate the desired outcome. 3

ods listing close; ods tagsets.excelxp path="c:\path" file="ods.xls" style=sansprinter options (autofilter='all' embedded_titles ='yes' autofit_height = yes frozen_headers='yes' frozen_headers='3'); ods tagsets.excelxp options(sheet_name='subject Names' absolute_column_width='10,11' ); proc print data = Test split= ' '; var name gender; ods tagsets.excelxp options(sheet_name='gender' absolute_column_width='10,11'); proc print data = Test split= ' '; var gender; ods tagsets.excelxp close; ods listing; LIMITATION 1. It is an xml file, which will take a round of procedure to import it back to SAS datasets once the spread sheets are generated. 2. Older versions than MS Excel 2002 cannot handle xml Extension files. For those who are using SAS version 9.2, variable labels as headers can be achieved quite simply by using the label statement in the PROC EXPORT. Figure 3: Output generated by ODS TAGSETS CONCLUSION While using SAS 9 and later versions, the EXCEL LIBNAME and ODS TAGSETS discussed in this paper greatly simplifies the task of generating multiple excel sheets and customized reports with variables labels as column headers. The ODS Tagsets have additional advantages that includes traffic lighting of the data and advanced customizing options, while EXCEL libname provides familiar and simpler SAS syntax and the usual SAS error log reporting. However, if the SAS version 9.2 is used, the label statement could be used to generate similar outputs. 4

REFERENCES SAS 9.1.3 XP Platform SAS Institute Inc., Cary, NC SAS OnlineDoc 9.1.3 for the Web SAS Institute Inc., Cary, NC SAS/ACCESS 9.1 Interface to PC Files: Reference Chapter 2 - The LIBNAME Statement for PC Files on Windows DelGobbo, V. 2007. Creating and importing multi-sheet excel workbooks the easy way with SAS. Proceedings of the SAS Global Forum 31, Paper 115. Available http://www2.sas.com/proceedings/sugi31/115-31.pdf DelGobbo, V. 2004, From SAS to Excel via XML, Available http://support.sas.com/rnd/papers/sugi29/excelxml.pdf ACKNOWLEDGMENTS The author would like to thank Mr. Carey Smoak & Mr. Mario Widel, Roche Molecular Systems and the management of MaxisIT Inc. for their support and guidance. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Chaitanya Chowdagam MaxisIT Inc., 203 Main Street, Metuchen, NJ 08840 (516)-448-3918 chowdagam@gmail.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. 5