Download presentation
Presentation is loading. Please wait.
Published byAnnabel Freeman Modified over 9 years ago
1
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks of Meta-Xceed Inc. in the USA and other countries. ® indicates USA registration. You use SAS®, Your boss uses Excel, Guess where your results are going to appear! (Part 2): DIGGING DEEPER INTO ODS to put your SAS data and results into Excel. William E Benjamin Jr, Owl Computer Consultancy, LLC, Phoenix, Arizona
2
Agenda The Problem - Moving Data to Excel Using ODS Early Methods – DDE, CSV and others A New Method – ODS and Tagsets What is a “Tagset” ? How do You find a Tagset How does a Tagset Work?
3
Agenda Focus - SAS Data to Excel via ExcelXP Tagset Getting the new SAS updated ExcelXP Installing the ExcelXP Tagset Understanding the ExcelXP tagset
4
Agenda Using the ExcelXP Tagset −Hello World Project −Tagset options −Style Commands −Using SAS Vars as Excel Formulas −SAS Can Send Hyperlinks to Excel −Create Multi-Sheet workbooks −Table of Contents – Click to Your Desired Page Conclusion
5
The Problem – Data to Excel Most Company PC’s have Excel Installed Many Company Programmers/Analysts use SAS Programmers Collect and Report the Data Management Often Uses Excel Managers Use and Explain the Results Within Excel
6
The Problem – Data to Excel Many Ways to Convert from SAS to Excel Dissimilar Results from Different Methods Most Transfer Methods Require Manual Excel Editing to produce final results
7
An Early Method – DDE One of the first transfer methods Available from the SAS Data step Based Upon Microsoft Standards Time intensive to Setup for use Cell by Cell control of Excel results Not Available in SAS® Enterprise Guide Subject of a Previous Paper
8
An Early Method – CSV One of the first transfer methods Available from the SAS Data step One of the first ODS output destinations Simple to use Limited control of Excel results May Require Manual Formatting in Excel
9
An Early Method – CSV PROC EXPORT DATA=SASHELP.SHOES OUTFILE="C:\wuss_2010\Shoes_1a.csv" DBMS=CSV REPLACE; Run;
10
An Early Method – CSV Here is a sample of the output file: "Obs","Region","Product","Subsidiary","Stores","Sales","Inventory","Returns" " 1","Africa","Boot","Addis Ababa","12"," $29,761"," $191,821"," $769" " 2","Africa","Men's Casual","Addis Ababa"," 4"," $67,242"," $118,036"," $2,284" " 3","Africa","Men's Dress","Addis Ababa"," 7"," $76,793"," $136,273"," $2,433“ -- More data – "393","Western Europe","Sport Shoe","Rome","14"," $9,969"," $74,848"," $549" "394","Western Europe","Women's Casual","Rome"," 2"," $19,964"," $62,256"," $954"
11
An Early ODS Method – CSV ODS CSV body='f:\WUSS_2010\Shoes_1a.csv'; PROC PRINT DATA=SASHELP.SHOES ; RUN; ODS CSV CLOSE;
12
An Early ODS Method – CSV Here is a sample of the output file: "Obs","Region","Product","Subsidiary","Stores","Sales","Inventory","Returns" " 1","Africa","Boot","Addis Ababa","12"," $29,761"," $191,821"," $769" " 2","Africa","Men's Casual","Addis Ababa"," 4"," $67,242"," $118,036"," $2,284" " 3","Africa","Men's Dress","Addis Ababa"," 7"," $76,793"," $136,273"," $2,433“ - More data – "393","Western Europe","Sport Shoe","Rome","14"," $9,969"," $74,848"," $549" "394","Western Europe","Women's Casual","Rome"," 2"," $19,964"," $62,256"," $954"
13
A New Method - ODS & Tagsets
14
What is a “Tagset” ?
15
A New Method - ODS & Tagsets A “Tagset” is a “Mediator”
16
A New Method - ODS & Tagsets
17
How do You find a Tagset
18
A New Method - ODS & Tagsets
23
How does a Tagset Work?
24
A New Method - ODS & Tagsets SAS Code or Procedure Sends Data to ODS ODS Uses a Tagset to Direct / Encode Outputs Outputs are Formatted (XLM/HTML/Others) Target Programs Analyze the Outputs Target Programs Visualize the Data Target Programs Include Excel, Word, Adobe, Browsers
25
A New Method - ODS & Tagsets SAS Code ODS Data Title Footnote Proc XML/HTML 1 2 3 EXCEL MS/Word PDF Browser s
26
SAS Data to Excel via ExcelXP Getting the new SAS updated ExcelXP http://support.sas.com/rnd/base/ods/odsmarkup/excltags.tpl As of October 16, 2010 the version available was SAS 9.1.3 Compatible, v1.116, 08/25/10
27
SAS Data to Excel via ExcelXP Installing the ExcelXP Tagset Save Tagset file somewhere to load into the SAS Editor Load the Tagset code into the SAS editor (NOTE * You Need the ability to write to SASUSER libname) Execute the Tagset code by any way you want. (Choose a “RUN” option, PF Key, or click the “Running Man Icon”)
28
SAS Data to Excel via ExcelXP
29
SASUSER and SASHELP May both be writable Only write into SASUSER Path order is Important
30
SAS Data to Excel via ExcelXP Understanding the ExcelXP tagset Start by Executing the following SAS Program: ODS tagsets.excelxp file="test.xml" options(doc="help"); Run;
31
Understanding the ExcelXP tagset The Results Will be Something Like This A Listing Will be Produced followed by a message (the listing may be at least an 8 page printed help file): ========================================================== NOTE: This is the Excel XP tagset (Compatible with SAS 9.1.3 and above, v1.116, 08/25/10). Add options(doc='help') to the ods statement for more information.
32
That is why they are there !!!! READ THE INSTRUCTIONS !
33
? Understanding the ExcelXP tagset
34
Tagset Code does not run sequentially Tagset Code Units are Defined Tagset Code Units are Triggered Tagset Code Units are Similar to Macros Tagset Code Units are Magical If You do not write them, …. THAT IS ALL YOU NEED TO KNOW Understanding the ExcelXP tagset
35
Using the ExcelXP Tagset Declare You want to use the ExcelXP Tagset ods tagsets.excelxp file=‘c:\my_file.xls’;
36
Using the ExcelXP Tagset Let’s start simple: The Hello World Project… (Shamelessly borrowed directly from the ExcelXP Tagset Help output listing…)
37
Hello World Project *Get Started – Open a Tagset and an Excel file (*.xml); ods tagsets.excelxp file='test1.xml' options(zoom='75');
38
Hello World Project data test; length a b 8 c $20; input a b c $; cards; 1 2 3 2 3 =RC[-2]+RC[-1] 3 4 =RC[-2]+RC[-1].. =SUM(R[-3]C:R[-1]C) run;
39
Hello World Project * Option added to hide spreadsheet periods; Options missing = ‘ ‘; proc print noobs; var a b; var c / style(head) = {flyover="Hello World"} style(data) = {cellwidth=50pt}; run;
40
Hello World Project * Now end the job; ods tagsets.excelxp close; run; * added to reset the default missing display; Options missing = ‘.’;
41
Hello World Project
43
Tagset options Let us examine some simple tagset options 1.zoom='75' 2.sheet_interval='bygroup' 3.sheet_label='By ' 4.row_heights='40'
44
Tagset options ods tagsets.excelxp file='test3.xml' options(zoom='75' sheet_interval='bygroup' sheet_label='By ' row_heights= '40');
45
Tagset options Lets get some simple data(straight from SAS); proc sort data=sashelp.shoes out=tmp; by Region Product Sales; run;
46
Tagset options Now Print the sorted file; proc print data=tmp noobs; by region ; sum sales; var product; var sales / style(data) = {cellwidth=50pt }; Run;
47
Tagset options * Now quit; ods tagsets.excelxp close; run;
48
Tagset options
49
Style Commands SAS9 Reporting Procedure Styles Tip Sheet
50
Style Commands One Simple command: var sales / style(data) = {cellwidth=50pt };
51
Using SAS Vars as Excel Formulas Data converted to a formula: Remember this data: =SUM(R[-3]C:R[-1]C) In Excel you saw: 15 Which really was =sum(c2:c4) in Excel-eaze
52
Using SAS Vars as Excel Formulas Everything is relative to the current cell! 15 was in cell ‘c5’ So… =SUM(R[-3]C:R[-1]C) Means add the column of cells in the current row minus 3, and the current column; until the current row minus 1, and the current column. Then put the result here. (3+5+7=15)
53
SAS Can Send Hyperlinks to Excel ods tagsets.excelxp file='Z:\WUSS_2010\test5.xml' style =Gears ; proc sort data=sashelp.shoes out=shoes1; by Region Product Subsidiary Sales ; run;
54
SAS Can Send Hyperlinks to Excel *remove spaces, special chars from var used as sheet name (Primary By variable); data shoes1; set shoes1; x = 1; do until (x eq 0); x = index(left(trim(region)),' /') ; region = translate(left(trim(region)),'_',' '); region = translate(region,'_','/'); end; drop x; run;
55
SAS Can Send Hyperlinks to Excel ods tagsets.excelxp options (sheet_label = 'Table of contents') ; title1 'Worldwide Show Sales by Region‘; data comments (keep=comments); retain counter 1; attrib comments length = $ 90; comments = '____________________________'; output; comments = 'This Excel Workbook contains '; output; comments = 'several sheets with one for '; output; comments = 'each region of the world '; output; comments = '____________________________'; output; comments = ' Regions displayed '; output; comments = '____________________________'; output; comments = 'Left Click title to see data '; output; comments = '____________________________'; output;
56
SAS Can Send Hyperlinks to Excel * output one record for each region; do until (eof); set shoes1 end=eof; by region; if first.region then do; counter + 1; *Build an Excel hyperlink to a new page in same workbook; comments = '=HYPERLINK("[test5.xml]' || left(trim(put(region,$char30.))) || '!A1", "' || left(trim(put(region,$char30.))) '")'; output; end;
57
SAS Can Send Hyperlinks to Excel * write text at bottom of table of contents page; comments = '____________________________'; output; comments = ' CAUTION - CHANGING THE '; output; comments = ' NAME OF THE WORKBOOK '; output; comments = ' MAY INVALIDATE THE '; output; comments = ' HYPERLINKS IN THE FILE '; output; comments = '____________________________'; output; stop; proc print data=comments noobs label; run;
58
Create Multi-Sheet workbooks ods tagsets.excelxp options(zoom='75' sheet_interval='bygroup' sheet_label=' ' row_heights= '40,20' Gridlines= 'Yes ') ; proc print data=shoes1 noobs; by region ; sum sales; var product Subsidiary / style(data) = {font_size=14pt}; var sales / style(data) = {cellwidth=50pt font_size=12pt}; run;
59
Create Multi-Sheet workbooks ***************************************************************; ** Close up and go home. **; ***************************************************************; ods tagsets.excelxp close; title; run;
60
-- Table of Contents -- Click to Your Desired Page
63
Conclusion WOW
64
Conclusion William E Benjamin Jr Owl Computer Consultancy, LLC Phoenix AZ William@OwlComputerConsultancy.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.