the 10 most frequently asked questions of exporting to · pdf filethe 10 most frequently asked...
Post on 31-Mar-2018
233 Views
Preview:
TRANSCRIPT
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
THE 10 MOST FREQUENTLY ASKED
QUESTIONS OF EXPORTING TO EXCEL®
CHEVELL PARKER
TECHNICAL SUPPORT ANALYST, SAS INSTITUTE INC.
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
Overview
• Methods used to Export to Excel
• Highlights of Exporting Features
• Top 10 FAQ’s
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
Exporting to Excel
ExcelODS
Access
E.G
Add-in
DDE
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
Selecting an Export Method
• ODS destinations:
ExcelXP
MSOffice2K
CSV
Other custom tagsets:
support.sas.com/rnd/base/ods/odsmarkup/index.html
o Tagsets.MSoffice2K_X
o Tagsets.TableEditor
• Dynamic data exchange (DDE): Very flexible
• EXPORT procedure: Use this procedure to read from and write to
Excel files.
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#10. Can I Execute a Visual Basic Macro?
• Dynamic Data Exchange (DDE) can be used to
execute a Visual Basic macro
• The MSOffice2K_X and the TableEditor tagsets point
to and Execute macros
• The Add-in can also be used execute Visual Basic
macros
filename maccmds dde 'excel|system';
data _null_;
file maccmds;
put '[run("timeperiod")]';
run;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#9. Can I Panel Tables or Graphs in a Worksheet?
• The MSOffice2K destination can be used along with ODS
Layout to panel tables
• The MSOffice2K_X and TableEditor tagsets use the
PANELCOLS= options to panel tables and graphics
• DDE can be used to place a table or graph at a specific
location on the worksheet
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#9. Can I Panel Tables or Graphs in a Worksheet ?
(Continued)
ods tagsets.msoffice2k_x file="c:\temp.xls"
style=normal options( panelcols="3");
proc means data=sashelp.prdsale mean min max;
title "Totals from Canada“;
where country="CANADA";
run;
...more code...
ods tagsets.msoffice2k_x options(panelcols="3");
proc report data=sashelp.prdsale(obs=10) nowd
style(header)={background=lightblue};
column region division actual predict;
where country="CANADA";
title "Details from Canada";
run;
..more code...
ods tagsets.msoffice2k_x close;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#9. Can I Panel Tables or Graphs in a Worksheet ? (Continued)
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#8. Can I Update an Excel Workbook ?
• Typically ODS does not allow updates to workbooks and
worksheets
• The sample TableEditor tagset allows update access on
the windows platform
• VBScript and DDE also both allow update of workbooks
and worksheets on windows
• PROC EXPORT and the Excel Libname engine also
allows updating
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#8 . Can I Update an Excel Workbook ? (Continued)
libname temp excel 'c:\temp\temp.xlsx‘;
data temp.’one’n;
set sashelp.class;
run;
filename CMDS dde 'excel|system';
data _null_;
file CMDS;
put '[Open("C:\temp\temp.xls")]';
put '[workbook.insert("c:\report1.xls")]';
put '[workbook.insert("c:\report2.xls")]';
put '[workbook.insert("c:\report3.xls")]';
put '[workbook.insert("c:\report4.xls")]';
put '[ERROR("FALSE")]';
put '[quit()]';
run;
Excel Libname Engine
DDE
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#7. How can I Generate Pivot Tables In
SAS?
• The TableEditor tagset can be used to generate
pivot tables
• The tagset uses Microsoft objects that also allow
the creation of pivot charts and other features
• VBScript and DDE and the ADD-In product can
also generate pivot tables
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#6. Can I Add an Image or Logo to the
Worksheet?
• The ExcelXP destination does not allow images
• The MSOffice2K destination can use the
PREIMAGE= attribute
• The MSOffice2K_X custom tagset can use
options to display images
• DDE can inert images into a provided range
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#6. Can I Add an Image or Logo to the Worksheet? (Continued)
ods tagsets.msoffice2k_x file="c:\temp.xls"
options(image_path="c:\temp\sas.gif”
image_height="100”
image_width="200");
proc print data=sashelp.class;
run;
ods tagsets.msoffice2k_x close;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
• The ExcelXP tagset provides options to coincide with
most of the Excel page setup and printing options
• The MSOffice2K destination allows the use of Microsoft
Office specific CSS style properties
• Options can be passed with the MSOffice2K_X tagset to
modify page setup
• DDE can supply Excel macro commands to provide
update of page setup information
#5. Can I Modify Page Setup Information?
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#5. Can I Modify Page Setup Information? (Continued)
ods tagsets.excelxp file="temp.xml"
options(orientation="landscape“
print_header=‘&L Page &n of &P’
print_footer=‘&R Confidential’
gridlines="yes”
scale=“80”
row_repeat=“3”
blackandwhite="yes");
proc print data=sashelp.class;
Title;
run;
ods tagsets.excelxp close;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#5. Can I Modify Page Setup Information?
(Continued)
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
• This warning message is caused by a new Microsoft
feature called "Extension Hardening"
• The dialog can be removed by modifying the Windows
registry
• Using the .XML extension prevents the dialog using
ExcelXP destination
#4. Why do I now get Excel Dialog Warnings
Opening .XLS files?
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#3. How Can I Generate Multiple Worksheets Per Workbook?
• The ExcelXP tagset generates multiple worksheets per
workbook by default
• Custom tagset MSOffice2K_X uses existing files to
update workbook
• DDE can be used to insert sheets into an existing
workbook
• The TableEditor tagset creates a worksheet from each
table unless specified
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#3. How Can I Generate Multiple Workbooks
Per Worksheet ? (Continued)
ods tagsets.excelxp file="c:\temp.xml";
ods tagsets.excelxp
options(sheet_name="Class");
proc print data=sashelp.class;
Run;
ods tagsets.excelxp
options(sheet_name="Air");
proc print data=sashelp.air;
run;
ods tagsets.excelxp close;
Sheet name
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#3. How Can I Generate Multiple Workbooks
Per Worksheet ? (Continued)
ODS Tagsets.MSOffice2k_x file=’test.xls’
Options (Frozen_Headers=’3’
Frozen_RowHeaders=’1’
AutoFilter=’Header’
Sheet_Name=‘Sample’
Orientation=“Landscape” );
(Worksheet_Source=“Table_1#C\temp.html,
Table_2#C\temp1.html,
Table_3#C\temp2.html,
Table_4#C\temp3.html,
Table_5#C\temp4.html,
Table_6#C\temp5.html,
Graph_1#C\temp6.html”);
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2. How Can I Retain my Leading Zero?
• The General format is used by Excel when no format is
applied
• The TAGATTR= attribute provides the ability to supply an
Excel format with the ExcelXP tagset
• The MSOffice2Kdestinations use the HTMLSTYLE=
attribute to supply an Excel format
• The CSV destination can use options to the tagset
• DDE can be used to add formatting to a range
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2 . How Can I Retain my Leading Zero?( Continued)
Destination Style Attribute Parameter Excel Version
ExcelXP TAGATTR= format: Excel 2002 +
MSOffice2k /
HTMLHTMLSTYLE=
mso-number-
formatExcel 2000 +
HTML3HTMLSTYLE/
HTMLCLASS
mso-number-
formatExcel 97+
CSV No Formatting N/A N/A
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2 . How Can I Retain my Leading Zero? (Continued)
Leading Range Scientific Thousands Character Number
1 21-Apr 1.23457E+17 1000 0.00E+00 45
2 20-May 3.33434E+17 2000 0.00E+00 48
3 21-Jun 1.23457E+17 3000 0.00E+00 67
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2 . How Can I Retain my Leading Zero?
(Continued)
Character Description
0 Pads the value with zeros.
# Does not display extra zeros.
? Leaves a space for insignificant zeros.
. (period) Displays decimal number.
% Multiplies by 100 and displays the value as a
percentage.
, (comma) Uses a thousands separator.
Text Code Description\character Displays the character that you specify.
"text" Displays the value as text.
* Repeats a character to fill the format.
_ (underscore) Skips the width of the next character.
@ Is a text placeholder.
Date Code Description
M/D/YYYY Formats a data as Month/Day/Year.
Miscellaneous Description[BLACK],
[BLUE],…[COLOR n]
Display the characters in the specified colors. n
is a value from 1 to 56 .
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2 . How Can I Retain my Leading Zero? (Continued)
ods tagsets.excelxp file="temp.xls" style=normal;
proc print data=one;
format leading z4.;
var leading / style(data)={tagattr="format:@"};
var range / style(data)={tagattr="format:@"};
var scientific / style(data)={tagattr="type:String"};
var thousands / style(data)={tagattr="format:#,###"};
var character / style(data)={tagattr="format:@"};
var number / style(data)={tagattr="format:##"};
run;
ods tagsets.excelxp close;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#2 . How Can I Retain my Leading Zero?
(Continued)
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#1. How Can I Reduce the Size of Files Generated with ODS ?
• Save file from Excel using the native file format
• Use VBScript to covert files in a directory
• Use the CSV destination if no formatting required
• Re-save file using DDE or the TableEditor tagset
to native Excel file on windows
• Use PROC EXPORT or the Excel Libname engine
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#1. How Can I Reduce the Size of Files
Generated with ODS ? (CONTINUED)
options noxwait noxsync;
filename cmds dde 'excel|system';
data _null_;
file cmds;
X=SLEEP(10);
put "[open(""C:\temp\temp.xml"")]";
put '[ERROR("FALSE")]';
put "[SAVE.AS(""C:\temp\temp.xlsx"",51)]";
X=SLEEP(2);
put '[close("false")]';
run;
Open worksheet
Save worksheet
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#1. How Can I Reduce the Size of Files Generated with
ODS ? (CONTINUED)
Ods tagsets.tableeditor file=”temp.html”
options(update_target=”c:\\temp\\test.xml”
excel_save_file=”c:\\temp\\test.xlsx”);
data _null_;
file print;
put “Save as Excel”;
run;
Ods tagsets.tableeditor close;
Copyr i g ht © 2012, SAS Ins t i tu t e Inc . A l l r ights reser ve d .
#1. How Can I Reduce the Size of Files Generated with ODS ? (CONTINUED)
SAS Program
XML createdConvert files
Create output
top related