Preserving Line Breaks When Exporting to Excel Nelson Lee, Genentech, South San Francisco, CA



Similar documents
Let SAS Modify Your Excel File Nelson Lee, Genentech, South San Francisco, CA

SAS to Excel with ExcelXP Tagset Mahipal Vanam, Kiran Karidi and Sridhar Dodlapati

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

Methodologies for Converting Microsoft Excel Spreadsheets to SAS datasets

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

Programming Tricks For Reducing Storage And Work Space Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA.

Anyone Can Learn PROC TABULATE

Writing Data with Excel Libname Engine

PharmaSUG Paper CC30

Combining SAS LIBNAME and VBA Macro to Import Excel file in an Intriguing, Efficient way Ajay Gupta, PPD Inc, Morrisville, NC

PharmaSUG Paper QT26

Report Customization Using PROC REPORT Procedure Shruthi Amruthnath, EPITEC, INC., Southfield, MI

Integrating SAS and Excel: an Overview and Comparison of Three Methods for Using SAS to Create and Access Data in Excel

Managing very large EXCEL files using the XLS engine John H. Adams, Boehringer Ingelheim Pharmaceutical, Inc., Ridgefield, CT

EXST SAS Lab Lab #4: Data input and dataset modifications

SAS Programming Tips, Tricks, and Techniques

Customized Excel Output Using the Excel Libname Harry Droogendyk, Stratia Consulting Inc., Lynden, ON

Paper FF-014. Tips for Moving to SAS Enterprise Guide on Unix Patricia Hettinger, Consultant, Oak Brook, IL

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.

Search and Replace in SAS Data Sets thru GUI

ABSTRACT INTRODUCTION SAS AND EXCEL CAPABILITIES SAS AND EXCEL STRUCTURES

Paper Creating Variables: Traps and Pitfalls Olena Galligan, Clinops LLC, San Francisco, CA

Importing Excel File using Microsoft Access in SAS Ajay Gupta, PPD Inc, Morrisville, NC

A Recursive SAS Macro to Automate Importing Multiple Excel Worksheets into SAS Data Sets

Mail Merge Creating Mailing Labels 3/23/2011

THE HELLO WORLD PROJECT

Downloading Your Financial Statements to Excel

Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

GEORGETOWN MANAGEMENT SYSTEM (GMS): Report GU Non Payroll Journals for Accounting Journal Template

Simple Rules to Remember When Working with Indexes Kirk Paul Lafler, Software Intelligence Corporation, Spring Valley, California

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

Using Pharmacovigilance Reporting System to Generate Ad-hoc Reports

Import and Output XML Files with SAS Yi Zhao Merck Sharp & Dohme Corp, Upper Gwynedd, Pennsylvania

ODS for PRINT, REPORT and TABULATE

Web Reporting by Combining the Best of HTML and SAS

Create an Excel report using SAS : A comparison of the different techniques

ing Automated Notification of Errors in a Batch SAS Program Julie Kilburn, City of Hope, Duarte, CA Rebecca Ottesen, City of Hope, Duarte, CA

Using SAS Enterprise Business Intelligence to Automate a Manual Process: A Case Study Erik S. Larsen, Independent Consultant, Charleston, SC

Essential Project Management Reports in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

SAS ODS HTML + PROC Report = Fantastic Output Girish K. Narayandas, OptumInsight, Eden Prairie, MN

MS Excel Template Building and Mapping for Neat 5

Embedded Special Characters Kiran Karidi, Mahipal Vanam, and Sridhar Dodlapati

Managing Tables in Microsoft SQL Server using SAS

SAS UNIX-Space Analyzer A handy tool for UNIX SAS Administrators Airaha Chelvakkanthan Manickam, Cognizant Technology Solutions, Teaneck, NJ

Spelling Checker Utility in SAS using VBA Macro and SAS Functions Ajay Gupta, PPD, Morrisville, NC

Data Export User Guide

The Essentials of Finding the Distinct, Unique, and Duplicate Values in Your Data

Simulate PRELOADFMT Option in PROC FREQ Ajay Gupta, PPD, Morrisville, NC

DBF Chapter. Note to UNIX and OS/390 Users. Import/Export Facility CHAPTER 7

Qualification Specification

Using Proc SQL and ODBC to Manage Data outside of SAS Jeff Magouirk, National Jewish Medical and Research Center, Denver, Colorado

PharmaSUG 2014 Paper CC23. Need to Review or Deliver Outputs on a Rolling Basis? Just Apply the Filter! Tom Santopoli, Accenture, Berwyn, PA

Introduction to SAS Business Intelligence/Enterprise Guide Alex Dmitrienko, Ph.D., Eli Lilly and Company, Indianapolis, IN

Contract Management Submittal Log Import Importing the Submittal Items From MS Excel

Beyond the Simple SAS Merge. Vanessa L. Cox, MS 1,2, and Kimberly A. Wildes, DrPH, MA, LPC, NCC 3. Cancer Center, Houston, TX.

Demystifying PROC SQL Join Algorithms Kirk Paul Lafler, Software Intelligence Corporation

The first thing to do is choose if you are creating a mail merge for printing or an merge for distribution over .

Flat Pack Data: Converting and ZIPping SAS Data for Delivery

Mail Merge Microsoft Word and Excel Queries Scott Kern Senior Consultant

Instant Interactive SAS Log Window Analyzer

An Introduction to SAS/SHARE, By Example

Data Presentation. Paper Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs

Tales from the Help Desk 3: More Solutions for Simple SAS Mistakes Bruce Gilsen, Federal Reserve Board

How are tags and messages archived in WinCC flexible? WinCC flexible. FAQ May Service & Support. Answers for industry.

Importing Excel Files Into SAS Using DDE Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

Creating HTML Output with Output Delivery System

IBM Unica emessage Version 8 Release 6 February 13, User's Guide

Downloading, Configuring, and Using the Free SAS University Edition Software

Oh No, a Zero Row: 5 Ways to Summarize Absolutely Nothing

From Database to your Desktop: How to almost completely automate reports in SAS, with the power of Proc SQL

UNIX Comes to the Rescue: A Comparison between UNIX SAS and PC SAS

Exporting Client Information

Experiences in Using Academic Data for BI Dashboard Development

OpenArray Sample Tracker Software

NØGSG DMR Contact Manager

9.1 SAS/ACCESS. Interface to SAP BW. User s Guide

LOCF-Different Approaches, Same Results Using LAG Function, RETAIN Statement, and ARRAY Facility Iuliana Barbalau, ClinOps LLC. San Francisco, CA.

Guido s Guide to PROC FREQ A Tutorial for Beginners Using the SAS System Joseph J. Guido, University of Rochester Medical Center, Rochester, NY

Listings and Patient Summaries in Excel (SAS and Excel, an excellent partnership)

Aspose.Cells Product Family

Gantt Chart for Excel

Beyond the Basics: Advanced REPORT Procedure Tips and Tricks Updated for SAS 9.2 Allison McMahill Booth, SAS Institute Inc.

Chapter 2 The Data Table. Chapter Table of Contents

Exporting Contact Information

Using SAS to Create Graphs with Pop-up Functions Shiqun (Stan) Li, Minimax Information Services, NJ Wei Zhou, Lilly USA LLC, IN

Computer Skills: Levels of Proficiency

Essential Time & Attendance Supervisor Scheduling Basics

Excel Templates. & Quote/Invoice Maker for ACT! Another efficient and affordable ACT! Add-On by V

Transcription:

PharmaSUG 2014 Paper CC07 Preserving Line Breaks When Exporting to Excel Nelson Lee, Genentech, South San Francisco, CA ABSTRACT Do you have imported data with line breaks and want to export the data to Excel? What if you need to preserve the line breaks in the data export? This paper shares a quick tip on how to export SAS data with line breaks to Excel through PROC TEMPLATE and TAGSET attributes. This paper was written for audiences with beginner skills; the code was written using SAS Version 9.2 on Windows operating system. INTRODUCTION It is common to enter line breaks (Alt+Enter) into Excel data to create multiple lines within a cell for easy reading or other formatting purposes. Exhibit 1 is an example where investigational subject data with comments are recorded. On row 2, the COMMENT column has multiple lines entered. A number of published articles 1,2 shared different approaches on importing this type of data in SAS from Excel. However, there are times that we need to preserve the data with line breaks when exporting to Excel. 3 lines separated by line breaks Exhibit 1: Source Data Sheet1 AN EXAMPLE Exhibit 2: Source Data Sheet2 Data in Exhibit 1 and Exhibit 2 come from two different sources but are in the same Excel file. There is a business need to combine (merge by ID) the 2 data sets into a single data set and export to Excel in a single spreadsheet. To complete this task, data in Exhibit 1 (sheet1) and Exhibit 2 (sheet2) are read in SAS using the LIBNAME statement. The following SAS code reads the data from the 2 spreadsheets (sheet1 and sheet2), manipulates the data and creates a single dataset, then exports the combined data to Excel.

/*read sheet1 COMMENT data*/ /*read sheet2 TEST data*/ DATA in_two; set test.'sheet2$'n; PROC SORT data=in_one; PROC SORT data=in_two; /*merge sheet1 and sheet2 data by ID, data are sorted by ID*/ DATA one_two; merge in_one in_two; ods listing close; ods tagsets.excelxp file="linebreakoutput.xls"; /* export to Excel */ ods tagsets.excelxp options(sheet_name="combined" Absolute_Column_Width="5,8,8,20,5,5" autofit_height = 'yes'); PROC PRINT data=one_two noobs; ods tagsets.excelxp close; ods listing; Exhibit 3 is the exported data in Excel. Note that the data in the COMMENT column is exported successfully but the line breaks are not preserved. For example, the first data line (row 2), a single line is observed where the line break is replaced with a space. Line break character is replaced by a space Line break character is replaced by a space LINE BREAK HANDLING Exhibit 3: Combined Data Line Breaks Are Not Preserved Since the variable COMMENT has line breaks (refer to Exhibit 1), it needs special handling in order to preserve line breaks. In the code below, the TRANWRD function replaces a line break (special embedded character 0A x) with the special character ^. It can be any character as long as it does not mix up with any character in COMMENT. Without this character conversion, the line break is completely ignored when data is read in SAS and treated as a space (see Exhibit 3). Page 2 of 5

/*read sheet1 COMMENT data with line breaks*/ COMMENT=tranwrd(COMMENT, '0A'x, "^"); /*replace line breaks*/ EXPORT TO EXCEL Use PROC TEMPLATE and modify TAGSET attributes to preserve line breaks in data export. Without this modification, the line breaks are not preserved during export and would have the character ^ exported instead as shown in Exhibit 4. Each line break is replaced by the special character ^ Exhibit 4: Combined Data Line Breaks Converted to a Special Character The following code (PROC TEMPLATE) is added before exporting the merged SAS dataset one_two in the previous section. This will allow the converted line break character ^ to export to Excel and preserve the line break attribute as shown in Exhibit 5. PROC TEMPLATE; edit tagsets.excelbase; mapsub = %nrstr("/</>/&/"/ "); map = %nrstr("<>&""^"); end; Unicode &#10 is the line break character ^ matches the line break replacement character in data in_one step Line break preserved CONCLUSIONS Exhibit 5: Desired Output Line Breaks Are Preserved The purpose of this paper is to show that with a simple special character conversion and modification to tagset attributes, you can easily export SAS data to Excel while preserving (or creating) the line break attributes. Page 3 of 5

ACKNOWLEDGEMENTS A big thank you to SAS technical support for assisting me with addressing the line break export question and identifying a solution. REFERENCE 1. Reading an Excel Spreadsheet with Cells Containing Line Endings, Larry Hoyle, Institute for Policy & Social Research, University of Kansas, SAS Global Forum 2013 Quick Tips, paper 315-2013 2. Line Feeds How to detect them and get rid of them? Kalyani Kothapalli, MDS Pharma Services, Lincoln, NE, Pharmasug 2008, paper CC06 CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Nelson Lee, CCDM Genentech, Inc. 1 DNA Way, MS #88 South San Francisco, CA 94080 (650) 225-2121 lee.nelson@gene.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. Page 4 of 5

APPENDIX The following code generates the data shown in Exhibit 5. LIBNAME test C:\MYSAS\Data\Clinicallab.xls ; /*read sheet1 COMMENT data with line breaks*/ comment=tranwrd(comment, '0A'x, "^"); /*replace line breaks*/ /*read sheet2 TEST data*/ DATA in_two; set test.'sheet2$'n; PROC SORT data=in_one; PROC SORT data=in_two; /*merge sheet1 and sheet2 data by ID, data are sorted by ID*/ DATA one_two; merge in_one in_two; /* Add the ODS PATH statement so that this does not get overwritten in the SASUSER */ ods path work.templat(update) sashelp.tmplmst(read); PROC TEMPLATE; edit tagsets.excelbase; mapsub = %nrstr("/</>/&/"/ "); map = %nrstr("<>&""^"); end; ods listing close; ods tagsets.excelxp file="linebreakoutput.xls"; /* export to Excel */ ods tagsets.excelxp options(sheet_name="combined" Absolute_Column_Width="5,8,8,20,5,5" autofit_height = 'yes'); PROC PRINT data=one_two noobs; ods tagsets.excelxp close; ods listing; Page 5 of 5