You are on page 1of 21

Creating Multi-Sheet

Excel Workbooks
with ODS
David Shamlin
R&D Director

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


Agenda

1. Combine multiple HTML files (SAS 8)


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

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


1. Combine multiple HTML files

 Pros
• Works with SAS 8 & SAS 9
• Simple ODS HTML

 Cons
• Multiple files
• XML frameset code
• Formatting quirks

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


PROC HTML

PROC HTML Content

PROC HTML

filelist
(XML)
DATA
Frameset
_null_;

report.xls
(HTML)

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


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;

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


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>

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


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"> Header
<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>

Body

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

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


sas8.report.xls
Header

<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> Body
<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>

Footer

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


Creating the frameset

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>';

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


Creating the frameset (cont.)

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>';

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


Creating the frameset (cont.)

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>';
Report
run;
Copyright © 2003, SAS Institute Inc. All rights reserved. 11
Reducing the number of physical files
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:

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
Copyright © 2003, SAS Institute Inc. All rights reserved. 12
Agenda

1. Combine multiple HTML files (SAS 8)


2. Use Tagsets.ExcelXP (SAS 9)
3. Use Tagsets.MSOffice2K (SAS 9)

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


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

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


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

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


Tagsets.ExcelXP extras

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

 orientation=‘landscape;
 embedded_titles=‘yes’;
 frozen_headers=‘yes’;
 frozen_rowheaders=‘yes’;
 autofilter=‘all’|’3-5’;

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


Agenda

1. Combine multiple HTML files (SAS 8)


2. Use Tagsets.ExcelXP (SAS 9)
3. Use Tagsets.MSOffice2K (SAS 9)

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


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

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


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;
Report
ods tagsets.MSOffice2K close;
Copyright © 2003, SAS Institute Inc. All rights reserved. 19
Agenda

1. Combine multiple HTML files (SAS 8)


2. Use Tagsets.ExcelXP (SAS 9)
3. Use Tagsets.MSOffice2K (SAS 9)

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


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

You might also like