64
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

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

Embed Size (px)

Citation preview

Page 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

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

Page 2: 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

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?

Page 3: 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

Agenda

Focus - SAS Data to Excel via ExcelXP Tagset

• Getting the new SAS updated ExcelXP

• Installing the ExcelXP Tagset

• Understanding the ExcelXP tagset

Page 4: 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

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

Page 5: 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

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

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

An Early Method – CSV

PROC EXPORT DATA=SASHELP.SHOES

OUTFILE="C:\wuss_2010\Shoes_1a.csv"

DBMS=CSV REPLACE;

Run;

Page 10: 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

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"

Page 11: 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

An Early ODS Method – CSV

ODS CSV body='f:\WUSS_2010\Shoes_1a.csv';

PROC PRINT DATA=SASHELP.SHOES ;

RUN;

ODS CSV CLOSE;

Page 12: 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

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"

Page 13: 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

A New Method - ODS & Tagsets

Page 14: 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

A New Method - ODS & Tagsets

What is a “Tagset” ?

Page 15: 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

A New Method - ODS & Tagsets

A “Tagset” is a

“Mediator”

Page 16: 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

A New Method - ODS & Tagsets

Page 17: 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

A New Method - ODS & Tagsets

How do You find a Tagset

Page 18: 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

A New Method - ODS & Tagsets

Page 19: 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

A New Method - ODS & Tagsets

Page 20: 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

A New Method - ODS & Tagsets

Page 21: 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

A New Method - ODS & Tagsets

Page 22: 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

A New Method - ODS & Tagsets

Page 23: 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

A New Method - ODS & Tagsets

How does a Tagset Work?

Page 24: 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

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

Page 25: 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

A New Method - ODS & Tagsets

SAS Code ODS

Data

Title

Footnote

Proc

XML/HTML

<Header></Header><Body><Style ss:ID="parskip" ss:Parent="body"><Alignment/><ss:Borders><ss:Border ss:Position="Left" /><ss:Border ss:Position="Top" /><ss:Border ss:Position="Right" /><ss:Border ss:Position="Bottom" /></ss:Borders><Protection ss:Protected="1" /></Style></Row><Row ss:AutoFitHeight="1" ss:Height="15"><Cell ss:StyleID="data__r" ss:Index="1"><Data ss:Type="Number">1</Data></Cell><Cell ss:StyleID="data__r" ss:Index="2"><Data ss:Type="Number">2</Data></Cell><Cell ss:StyleID="data__l" ss:Index="3"><Data ss:Type="Number">3</Data></Cell></Row>

</Body>

EXCELM

S/Wor

dPDF

Browse

rs

Page 26: 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

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

Page 27: 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

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”)

Page 28: 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

SAS Data to Excel via ExcelXP

Page 29: 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

SAS Data to Excel via ExcelXP

SASUSER and

SASHELPMay both be

writable

Only write into

SASUSER

Path order is Important

Page 30: 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

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;

Page 31: 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

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.

Page 32: 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

That is why they are there !!!!

READ THE INSTRUCTIONS !

Page 33: 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

?Understanding the ExcelXP tagset

Page 34: 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

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

Page 35: 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

Using the ExcelXP Tagset

Declare You want to use the ExcelXP Tagset

ods tagsets.excelxp file=‘c:\my_file.xls’;

Page 36: 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

Using the ExcelXP Tagset

Let’s start simple:

The Hello World Project…

(Shamelessly borrowed directly from the ExcelXP Tagset Help output listing…)

Page 37: 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

Hello World Project

*Get Started – Open a Tagset and an Excel file (*.xml);

ods tagsets.excelxp file='test1.xml' options(zoom='75');

Page 38: 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

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;

Page 39: 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

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;

Page 40: 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

Hello World Project

* Now end the job;

ods tagsets.excelxp close;

run;

* added to reset the default missing display;

Options missing = ‘.’;

Page 41: 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

Hello World Project

Page 42: 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

Hello World Project

Page 43: 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

Tagset options

Let us examine some simple tagset options

1. zoom='75'

2. sheet_interval='bygroup'

3. sheet_label='By '

4. row_heights='40'

Page 44: 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

Tagset options

ods tagsets.excelxp file='test3.xml'

options(zoom='75'

sheet_interval='bygroup'

sheet_label='By '

row_heights= '40');

Page 45: 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

Tagset options

Lets get some simple data(straight from SAS);

proc sort data=sashelp.shoes out=tmp;

by Region Product Sales;

run;

Page 46: 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

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;

Page 47: 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

Tagset options

* Now quit;

ods tagsets.excelxp close;

run;

Page 48: 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

Tagset options

Page 49: 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

Style Commands

SAS9 Reporting Procedure

Styles Tip Sheet

Page 50: 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

Style Commands

One Simple command:

var sales / style(data) = {cellwidth=50pt };

Page 51: 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

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

Page 52: 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

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)

Page 53: 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

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;

Page 54: 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

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;

Page 55: 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

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;

Page 56: 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

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;

Page 57: 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

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;

Page 58: 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

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;

Page 59: 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

Create Multi-Sheet workbooks

***************************************************************;

** Close up and go home. **;

***************************************************************;

ods tagsets.excelxp close;

title;

run;

Page 60: 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

-- Table of Contents --Click to Your Desired

Page

Page 61: 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

-- Table of Contents --Click to Your Desired

Page

Page 62: 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

-- Table of Contents --Click to Your Desired

Page

Page 63: 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

Conclusion

WOW

Page 64: 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

Conclusion

William E Benjamin Jr

Owl Computer Consultancy, LLC

Phoenix AZ

[email protected]