Exporting Variable Labels As Column Headers In Excel Using .

2y ago
18 Views
2 Downloads
969.11 KB
5 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Amalia Wilborn
Transcription

Paper 74924-2011Exporting Variable Labels as Column Headers in Excel using SAS Chaitanya Chowdagam, MaxisIT Inc., Metuchen, NJABSTRACTExcel output is the desired format for most of the ad-hoc reports requested for an easy interpretation and explorationof data. However, to make these reports more informative variable labels could be used instead of variable names ascolumn header. This is harder to achieve by the conventional SAS Export procedure, PROC EXPORT. This paperwill provide easy and quick methods of exporting SAS data to multiple Excel sheets with variable labels as columnheaders using EXCEL Libname and ODS Markup.INTRODUCTIONExcel is a universal platform for simple data analysis, sharing information and data interpretation. There arenumerous 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 withoutany easy options of customizing the reports. Though DDE allows SAS to run VBA macros within the excel workbookand data formatting, it is not worth doing some laborious work for a simple formatted EXCEL output. Stepping to SAS9 and later versions, SAS has come up with EXCEL Libname and ODS Markup, a middle ground between the plaindata dump using PROC EXPORT and highly laborious DDE. The goal of this paper is to discuss these two methodsthat are available for SAS 9 and later versions, which are fairly simple to get the variable labels as column headers inEXCEL outputs.EXCEL LIBNAMEExcel 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 STARTEDTest Data Used for Demonstrationdata Test;attrib namelength 10gender length 8input name gender ;cards;Tom MaleMary FemaleGeorge MaleChristine FemaleJim MaleBeth Female;run;label 'Name of the Subject'label 'Gender at the time of Birth';1

THE BASIC EXCEL LIBNAME SYNTAXLIBNAME 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 STEPwith 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;run;quit;*Sheet-1 (Name of the sheet-Names);data myxlbook.Names(dblabel yes);set test;run;*Sheet-2 (Name of the sheet-Gender);data myxlbook.Gender(dblabel yes);set test;run;libname myxlbook clear;The output generated using the above code is shown isFigure1.DBLABEL YESDuring output to Excel, SAS variable labels, instead of variablenames, are written out to column headers by changing to thedata set option “DBLABEL YES”. All labels written in this waymust be unique. This allows long variable labels with spacesand special characters to be written from SAS into Excelcolumn headers (Explore more about the other dataset options).Figure 1: Output using Excel Libname engineTo 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;run;quit;The above code will delete the data present in the each sheet that has to be replaced with the new data. The log willrefer 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 bookTHINGS TO REMEMBERWhen 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 canbe 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 thedata is preserved as xml file.2.Customizing outputs by Adding filters to different fields lock the headers, dimensions of each cell, andadding 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 SYNTAXods 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 likePROC PRINT, PROC REPORT, PROC TABULATE can be used in ODS tagsets. But to get the variable labels ascolumn 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 sansPrinteroptions (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;run;ods tagsets.ExcelXP options(sheet name 'Gender' absolute column width '10,11');proc print data Test split ' ';var gender;run;ods tagsets.ExcelXP close;ods listing;LIMITATION1.It is an xml file, which will take a round of procedure toimport it back to SAS datasets once the spread sheetsare generated.2.Older versions than MS Excel 2002 cannot handle xmlExtension files.For those who are using SAS version 9.2, variable labels asheaders can be achieved quite simply by using the labelstatement in the PROC EXPORT.Figure 3: Output generated by ODS TAGSETSCONCLUSIONWhile using SAS 9 and later versions, the EXCEL LIBNAME and ODS TAGSETS discussed in this paper greatlysimplifies the task of generating multiple excel sheets and customized reports with variables labels as columnheaders. The ODS Tagsets have additional advantages that includes traffic lighting of the data and advancedcustomizing options, while EXCEL libname provides familiar and simpler SAS syntax and the usual SAS error logreporting. However, if the SAS version 9.2 is used, the label statement could be used to generate similar outputs.4

REFERENCESSAS 9.1.3 XP PlatformSAS Institute Inc., Cary, NCSAS OnlineDoc 9.1.3 for the WebSAS Institute Inc., Cary, NCSAS/ACCESS 9.1 Interface to PC Files: ReferenceChapter 2 - The LIBNAME Statement for PC Files on WindowsDelGobbo, V. 2007. “Creating and importing multi-sheet excel workbooks the easy way with SAS”. Proceedings ofthe SAS Global Forum 31, Paper 115. Available elGobbo, V. 2004, “From SAS to Excel via XML”,Available pdfACKNOWLEDGMENTSThe author would like to thank Mr. Carey Smoak & Mr. Mario Widel, Roche Molecular Systems and the managementof MaxisIT Inc. for their support and guidance.CONTACT INFORMATIONYour comments and questions are valued and encouraged. Contact the author at:Chaitanya ChowdagamMaxisIT Inc.,203 Main Street,Metuchen, NJ 08840(516)-448-3918chowdagam@gmail.comSAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SASInstitute Inc. in the USA and other countries. indicates USA registration.Other brand and product names are trademarks of their respective companies.5

During output to Excel, SAS variable labels, instead of variable names, are written out to column headers by changing to the . PROC PRINT, PROC REPORT, PROC TABULATE can be used in ODS tagsets. But to get the variable labels as . DelGobbo, V. 2007. “Creating and importing multi-sheet excel

Related Documents:

COLUMN LAYOUT Size of Each Column Tied Column Spiral Column Composition Column Axially Loaded Column Column With uniaxial Eccentric Loading Column With Biaxial Eccentric Loading . 1.Footing column Demarcation. 2.Column Steel Check 3.D.P.C. Level 4. Roof Shuttering 5.Roof Structure . 6. Electrical Wall 7. Sanitary Wall & Floor

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.

Using the Column Switching Template SCOUT Column Selector User Guide 3-13 3 For example, if you specify 3 runs for column 2A, 2 runs for column 2B, and 1 run for column 2C, the columns will be switched in the sequence shown in Table 3-1 . 3. Enter the number of runs for each column. 4. Click Run. The template runs. use the same column for

2013 Morrisey Technology & Educational Conference 7 Batch Labels Batch labels gives you the ability to do labels quickly on the fly. Batch labels give you the ability to use the criteria tab to select a population you want to create labels for. At the bottom of the screen you have the ability to define what address you labels will have on them and

Creating Mailing Labels from a Spreadsheet in OpenOffice Page 4 of 16 Part 3. Creating and Printing Labels 1. Once you have got the database set up in OpenOffice you are ready to go. 2. Choose File New Labels. 3. In the Labels tab of the Labels

Food & Beverage Industry Highlights, Litigation trends for 2016, Regulatory issues, Demo of Tracker Keywords "Craft" food labels, "Handcrafted" food labels, "Handmade" food labels, "Just" food labels, "Pure" food labels, "Pure" food labels, ACC v. OEHHA, American Chemistry Council, Antioxidants, Ascertainability, Blanket .

The labels give buyers accurate information about the foods they purchase. Food labels also help consumers keep food safe. Ms. Lara says that the U.S. Food and Drug Administration (FDA) requires labels. The FDA also tests foods to see that the labels are correct. Ms. Lara says that other foods sometimes have labels, too. For instance,

using Scrum for agile software project management in a university environment. The paper is divided into three parts. In the first part an overview of the Scrum method is given. In the second part .