Multi Sheet Excel Post

21
Copyright © 2003, SAS Institute Inc. All rights reserved. Creating Multi-Sheet Excel Workbooks with ODS David Shamlin R&D Director

Transcript of Multi Sheet Excel Post

Page 1: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved.

Creating Multi-Sheet Excel Workbooks with ODSDavid ShamlinR&D Director

Page 2: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 2

Agenda

1. Combine multiple HTML files (SAS 8)

2. Use Tagsets.ExcelXP (SAS 9)

3. Combine multiple files created using Tagsets.MSOffice2K (SAS 9)

Page 3: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 3

1. Combine multiple HTML files

Pros• Works with SAS 8 & SAS 9

• Simple ODS HTML

Cons• Multiple files

• XML frameset code

• Formatting quirks

Page 4: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 4

PROC

PROC

PROC

HTML

HTML

HTML

DATA _null_;

filelist(XML)

report.xls(HTML)

Frameset

Content

Page 5: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 5

ods html file='sas8.by_region.htm' style=default;

proc tabulate data=sashelp.shoes;class region;var sales;table region, sales='Sales'*format=dollar20.0*sum='';

run;

ods html file='sas8.by_year.htm' style=default;

proc tabulate data=sashelp.retail;class year;var sales;table year='', sales='Sales (in M$)' *

format=dollar20.0 * sum=''/box='Year';run;

ods html file='sas8.details.htm' style=default;

proc print data=sashelp.shoes noobs;run;

ods html close;

Page 6: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 6

sas8.filelist.xml

<xml xmlns:o="urn:schemas-microsoft-com:office:office"> <o:MainFile href="sas8.report.xls"/> <o:File href="sas8.by_region.htm"/> <o:File href="sas8.by_year.htm"/> <o:File href="sas8.details.htm"/> <o:File href="sas8.filelist.xml"/></xml>

Page 7: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 7

sas8.report.xls<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name="Excel Workbook Frameset"><meta name="Generator" content="SAS Software, http://www.sas.com" sasversion="9.1"><meta http-equiv="Content-type" content="text/html"><meta name="ProgId" content="Excel.Sheet"><link rel=File-List href="sas8.filelist.xml"><!--[if gte mso 9]><xml>

</xml><![endif]--></head></html>

Body

Footer

Header

Page 8: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 8

sas8.report.xls

<x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>By Region</x:Name> <x:WorksheetSource HRef="sas8.by_region.htm"/> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>By Year</x:Name> <x:WorksheetSource HRef="sas8.by_year.htm"/> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>Detail</x:Name> <x:WorksheetSource HRef="sas8.details.htm"/> </x:ExcelWorksheet> </x:ExcelWorksheets></x:ExcelWorkbook>

Header

Footer

Body

Page 9: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 9

data _null_;

file "sas8.filelist.xml";

put '<xml xmlns:o="urn:schemas-microsoft-com:office:office">'; put ' <o:MainFile href="sas8.report.xls"/>'; put ' <o:File href="sas8.by_region.htm"/>'; put ' <o:File href="sas8.by_year.htm"/>'; put ' <o:File href="sas8.details.htm"/>'; put ' <o:File href="sas8.filelist.xml"/>'; put '</xml>';

Creating the frameset

Page 10: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 10

… file "sas8.report.xls";

put '<html xmlns:o="urn:schemas-microsoft-com:office:office"'; put ' xmlns:x="urn:schemas-microsoft-com:office:excel"'; put ' xmlns="http://www.w3.org/TR/REC-html40">'; put '<head>'; put '<meta name="Excel Workbook Frameset">'; put '<meta name="Generator" content="SAS Software, http://www.sas.com" sasversion="' "&SYSVER" '">'; put '<meta http-equiv="Content-type" content="text/html">'; put '<meta name="ProgId" content="Excel.Sheet">'; put '<link rel=File-List href="sas8.filelist.xml">'; put '<!--[if gte mso 9]><xml>';

Creating the frameset (cont.)

Page 11: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 11

… put '<x:ExcelWorkbook>'; put ' <x:ExcelWorksheets>'; put ' <x:ExcelWorksheet>'; put " <x:Name>By Region</x:Name>"; put ' <x:WorksheetSource HRef="sas8.by_region.htm"/>'; put ' </x:ExcelWorksheet>'; put ' <x:ExcelWorksheet>'; put " <x:Name>By Year</x:Name>"; put ' <x:WorksheetSource HRef="sas8.by_year.htm"/>'; put ' </x:ExcelWorksheet>'; put ' <x:ExcelWorksheet>'; put " <x:Name>Detail</x:Name>"; put ' <x:WorksheetSource HRef="sas8.details.htm"/>'; put ' </x:ExcelWorksheet>'; put ' </x:ExcelWorksheets>'; put '</x:ExcelWorkbook>'; put '</xml><![endif]-->'; put '</head>'; put '</html>';

run;

Creating the frameset (cont.)

Report

Page 12: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 12

Reducing the number of physical files

1. Open the XLS file in Excel

2. Select File > Save As…

3. Change Save as type from “Web Page” to “Microsoft Excel Workbook”

4. Change the File name field (optional)

5. Click Save

At this point, you have multiple physical files (one XLS file, one XML file, and and HTML file for each worksheet), you can turn these into a single XLS file:

Page 13: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 13

Agenda

1. Combine multiple HTML files (SAS 8)

2. Use Tagsets.ExcelXP (SAS 9)

3. Use Tagsets.MSOffice2K (SAS 9)

Page 14: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 14

2. Use Tagsets.ExcelXP (SAS 9)

Pros• Simpler SAS code

• Puts each SAS table on a different worksheet

• Smarter formating

• Options to control some formatting

• Extensible

Cons• Larger file

• Only available in SAS 9

• Experimental designation (but very robust!)

Page 15: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 15

ods tagsets.excelxp file='sas9.report.xls' style=sasweb;

title Sales by region;proc tabulate data=sashelp.shoes;

class region;var sales;table region, sales='Sales'

*format=dollar20.0*sum='';run;

title Sales by year;proc tabulate data=sashelp.retail;

class year;var sales;table year='', sales='Sales (in M$)' *

format=dollar20.0 * sum=''/box='Year';run;

title Sales detail;proc print data=sashelp.shoes noobs;run;

ods tagsets.excelxp close;Report

Page 16: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 16

Tagsets.ExcelXP extras

ods tagsets.excelxp options(doc=‘help’);

orientation=‘landscape;

embedded_titles=‘yes’;

frozen_headers=‘yes’;

frozen_rowheaders=‘yes’;

autofilter=‘all’|’3-5’;

Page 17: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 17

Agenda

1. Combine multiple HTML files (SAS 8)

2. Use Tagsets.ExcelXP (SAS 9)

3. Use Tagsets.MSOffice2K (SAS 9)

Page 18: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 18

1. Use Tagsets.MSOffice2K (SAS 9)

Similar to first technique

Pros• Formatting optimized for MS Office applications

• Supports SAS/GRAPH

Cons• Multiple files

• XML frameset code

• Only available in SAS 9

Page 19: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 19

ods tagsets.MSOffice2K file='sas9.by_region.htm' style=banker;

title Sales by region;

options device=activex;proc gchart data=sashelp.shoes;

vbar3d region / sumvar=sales;run;quit;

*ods tagsets.MSOffice2K file='sas9.by_year.htm' style=banker;

title Sales by year;proc tabulate data=sashelp.retail;

class year;var sales;table year='', sales='Sales (in M$)' *

format=dollar20.0 * sum=''/box='Year';run;

ods tagsets.MSOffice2K file='sas9.details.htm' style=banker;

title Sales detail;proc print data=sashelp.shoes noobs;run;

ods tagsets.MSOffice2K close;Report

Page 20: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 20

Agenda

1. Combine multiple HTML files (SAS 8)

2. Use Tagsets.ExcelXP (SAS 9)

3. Use Tagsets.MSOffice2K (SAS 9)

Page 21: Multi Sheet Excel Post

Copyright © 2003, SAS Institute Inc. All rights reserved. 21Copyright © 2003, SAS Institute Inc. All rights reserved. 21