maintaining formats when exporting data from sas into
play

Maintaining Formats when Exporting Data from SAS into Microsoft - PowerPoint PPT Presentation

Introduction Solutions Conclusions Maintaining Formats when Exporting Data from SAS into Microsoft Excel Nate Derby & Colleen McGahan Stakana Analytics, Seattle, WA BC Cancer Agency, Vancouver, BC SUCCESS 3/12/15 Nate Derby &


  1. Introduction Solutions Conclusions Maintaining Formats when Exporting Data from SAS into Microsoft Excel Nate Derby & Colleen McGahan Stakana Analytics, Seattle, WA BC Cancer Agency, Vancouver, BC SUCCESS 3/12/15 Nate Derby & Colleen McGahan Organizing SAS Files 1 / 24

  2. Introduction Solutions Conclusions Outline Introduction 1 Solutions 2 The ExcelXP Tagset Dynamic Data Exchange (DDE) The LIBNAME Engine Conclusions 3 Nate Derby & Colleen McGahan Organizing SAS Files 2 / 24

  3. Introduction Solutions Conclusions Introduction Many typical ways of exporting data from SAS into Excel destroy the data formats. Creating Data Formats DATA class; SET sashelp.class; FORMAT age 3. height weight 6.2; IF name = 'Thomas' THEN age = .; RUN; Nate Derby & Colleen McGahan Organizing SAS Files 3 / 24

  4. Introduction Solutions Conclusions SAS Dataset Nate Derby & Colleen McGahan Organizing SAS Files 4 / 24

  5. Introduction Solutions Conclusions Exporting SAS Data Now let’s export it via PROC EXPORT and the ExcelXP tagset: SAS Code PROC EXPORT DATA=class OUTFILE="&outroot\Output from PROC EXPORT.xls"; RUN; ODS tagsets.ExcelXP FILE="&outroot\Output from ExcelXP.xls"; PROC PRINT DATA=class; RUN; ODS tagsets.ExcelXP CLOSE; Nate Derby & Colleen McGahan Organizing SAS Files 5 / 24

  6. Introduction Solutions Conclusions PROC EXPORT Output Nate Derby & Colleen McGahan Organizing SAS Files 6 / 24

  7. Introduction Solutions Conclusions PROC EXPORT Output Nate Derby & Colleen McGahan Organizing SAS Files 7 / 24

  8. Introduction Solutions Conclusions ExcelXP Tagset Output Nate Derby & Colleen McGahan Organizing SAS Files 8 / 24

  9. Introduction Solutions Conclusions ExcelXP Tagset Output Nate Derby & Colleen McGahan Organizing SAS Files 9 / 24

  10. Introduction Solutions Conclusions SAS Formats vs. Excel Formats SAS Formats vs. Excel Formats SAS format Excel format Excel format name Text $8. @ Number, 2 decimal places 8.2 0.00 z8.2 00000.00 (none) Percentage, 2 decimal places percent8.2 0.00% mmddyy8. mm/dd/yy Date, type “03/14/01” Number, 2 decimal places, with ... comma12.2 #,##0.00 We need to translate SAS formats into Excel formats! Nate Derby & Colleen McGahan Organizing SAS Files 10 / 24

  11. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine ExcelXP Tagset Solution SAS Code ODS tagsets.ExcelXP FILE="&outroot\Output from ExcelXP, Numeric Formatting.xls"; PROC PRINT DATA=class; VAR name sex age; VAR height weight / STYLE={TAGATTR='format=0.00'}; RUN; ODS tagsets.ExcelXP CLOSE; Nate Derby & Colleen McGahan Organizing SAS Files 11 / 24

  12. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine ExcelXP Tagset Solution Nate Derby & Colleen McGahan Organizing SAS Files 12 / 24

  13. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine ExcelXP Tagset Solution with PROC TEMPLATE SAS Code PROC TEMPLATE; DEFINE STYLE styles.mystyle; PARENT = styles.default; STYLE data_num from data / TAGATTR='format:0.00'; END; RUN; ODS tagsets.ExcelXP FILE="&outroot\Output from ExcelXP, Numeric Formatting.xls"; PROC PRINT DATA=class; VAR name sex age; VAR height weight / STYLE( data )=data_num; RUN; ODS tagsets.ExcelXP CLOSE; Nate Derby & Colleen McGahan Organizing SAS Files 13 / 24

  14. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine Dealing with Missing Values SAS Code OPTIONS MISSING=''; ODS tagsets.ExcelXP FILE="&outroot\Output from ExcelXP, Numeric Formatting.xls"; PROC PRINT DATA=class; VAR name sex age; VAR height weight / STYLE( data )=data_num; RUN; ODS tagsets.ExcelXP CLOSE; OPTIONS MISSING='.'; Nate Derby & Colleen McGahan Organizing SAS Files 14 / 24

  15. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine Dynamic Data Exchange (DDE) Solution DDE = SAS opens Excel, tells it what to do. You have to tell Excel every single step. Best solution: The %exportToXL macro (free!). SAS Code %LET exroot = c:\...\exportToXL; OPTIONS SASAUTOS=( "&exroot" ) MAUTOSOURCE; %exportToXL( DSIN=class, SAVEPATH=&outroot, SAVENAME=Output from DDE ); Nate Derby & Colleen McGahan Organizing SAS Files 15 / 24

  16. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine Dynamic Data Exchange (DDE) Solution Nate Derby & Colleen McGahan Organizing SAS Files 16 / 24

  17. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution Requires the SAS/ACCESS for PC Files package. We “cheat” by (manually) formatting the Excel template ahead of time. We then pour the data into the template. Nate Derby & Colleen McGahan Organizing SAS Files 17 / 24

  18. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution Nate Derby & Colleen McGahan Organizing SAS Files 18 / 24

  19. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution Nate Derby & Colleen McGahan Organizing SAS Files 19 / 24

  20. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution Nate Derby & Colleen McGahan Organizing SAS Files 20 / 24

  21. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution SAS Code LIBNAME workbook PCFILES PATH="&outroot\Output from LIBNAME.xls"; PROC DATASETS LIBRARY=workbook NOLIST; DELETE MyRange; QUIT; DATA workbook.MyRange; SET class; RUN; LIBNAME workbook CLEAR; Nate Derby & Colleen McGahan Organizing SAS Files 21 / 24

  22. Introduction The ExcelXP Tagset Solutions Dynamic Data Exchange (DDE) Conclusions The LIBNAME Engine The LIBNAME Solution Nate Derby & Colleen McGahan Organizing SAS Files 22 / 24

  23. Introduction Solutions Conclusions Conclusions Many ways of exporting data from SAS into Excel destroy data formats. SAS and Excel speak different languages for data formats. This can be fixed in three ways: ExcelXP Tagset with the TAGATTR style. Dynamic Data Exchange with %exportToXL macro. The LIBNAME engine with pre-formatted template. Nate Derby & Colleen McGahan Organizing SAS Files 23 / 24

  24. Appendix Further Resources Too many to list – see the paper! Nate Derby: nderby@stakana.com Colleen McGahan: cmcgahan@bccancer.bc.ca Nate Derby & Colleen McGahan Organizing SAS Files 24 / 24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend