Download presentation
Presentation is loading. Please wait.
Published bySybil Bates Modified over 8 years ago
1
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William E Benjamin Jr Owl Computer Consultancy, LLC
2
Copyright 2009 Topic Groups LIBNAME – SYNTAX and DEFAULTS ENGINE-CONNECTION-OPTIONS LIBNAME-OPTIONS DATASET-OPTIONS EXAMPLES QUESTIONS Copyright 2008
3
Copyright 2009 LIBNAME – SYNTAX and DEFAULTS Simple Syntax Example Part of the syntax (SAS Version 9.2) for accessing Excel files is as follows: LIBNAME libref ; That looks pretty much like every other LIBNAME definition. So let’s make it a little more Excel friendly. LIBNAME xls_data EXCEL ‘C:\WUSS_2009\My_Excel_File.xls’; Default Syntax
4
Copyright 2009 LIBNAME – SYNTAX and DEFAULTS Simple Syntax Example LIBNAME xls_data EXCEL ‘ C:\WUSS_2009\My_Excel_File.xls ’; This LIBNAME reaches to a FILE not a DIRECTORY Because the file contains other objects Default Syntax
5
Copyright 2009 LIBNAME – SYNTAX and DEFAULTS Simple Syntax Example Create a Simple Excel File from a SAS File: Data xls_data.’sheet1’n; Set sashelp.shoes; Run; Create an EXCEL file from a SAS File
6
Copyright 2009 LIBNAME – SYNTAX and DEFAULTS Simple Syntax Example ‘sheet1’n is a “named constant” used to identify the Excel Sheet name. Data xls_data. ’sheet1’n ; Set sashelp.shoes; Run; Default Syntax
7
Copyright 2009 LIBNAME – SYNTAX and DEFAULTS Simple Syntax Example – After Execution
8
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax LIBNAME libref ; Now we see ”engine-connection-options” and “libname-options”, these are both little used features of the SAS LIBNAME statements. We will examine these in order and list some examples and outputs from applying these options. Excel Related Syntax
9
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax HEADER OPTION – HEADER=YES|NO LIBNAME xls_data EXCEL ‘C:\WUSS_2009\My_Excel_File.xls’ HEADER=NO; HEADER=YES is the Default and is implied when not used on LIBNAME statement. ENGINE-CONNECTION-OPTIONS - Example
10
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax HEADER OPTION – HEADER=YES|NO Changes how the first line of the Excel file is Read YES (Default) – Convert Line 1 of Excel sheet to SAS Variable names NO – Line 1 of Excel Sheet is Data Generate Variable names (F1,F2) Data in row 1 is subject to “Best-Guess” rules of data conversion Invalid SAS Variable name characters are converted to “_” Duplicate names are avoided by adding a number to end of SAS Name ENGINE-CONNECTION-OPTIONS
11
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax
12
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax MIXED OPTION – MIXED=YES|NO LIBNAME xls_data EXCEL ‘C:\WUSS_2009\My_Excel_File.xls’ MIXED=YES; MIXED=NO is the Default and is implied when not used on LIBNAME statement. ENGINE-CONNECTION-OPTIONS - Example
13
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax MIXED OPTION – MIXED=YES|NO Changes how All of the Excel data is Read into SAS for this file NO (Default) – a specified number of rows of the Excel column are searched and a guess is returned about the data type of the input Excel data field. YES– ALL SAS variables are crated as character variables Excel file is read in import mode No updates are allowed to the file The Windows Registry can be changed to modify this behavior, but it will change the behavior for all programs that use the Microsoft Jet/Excel engine. ENGINE-CONNECTION-OPTIONS
14
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax
15
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax
16
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax VERSION OPTION – VERSION= '2003', '2002', '2000', '97', '95', or '5' LIBNAME xls_data EXCEL ‘C:\WUSS_2009\My_Excel_File.xls’ VERSION=97; This option is only valid for Excel Output VERSION=97 is the Default and is implied when not used on LIBNAME statement. Only two file formats are available (EXCEL5, and EXCEL 97 - 2003) Quotes are optional ENGINE-CONNECTION-OPTIONS - Example
17
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax VERSION OPTION – VERSION= '2003', '2002', '2000', '97', '95', or '5' ** NOTE ** Microsoft Excel 2007 is not Supported by SAS/ACCESS for PC files, but Excel 2007 can read all other formats. Data stored in Microsoft Excel 2007 file format (*.xlsx) is stored as components of a “ZIP” file and not supported by SAS/ACCESS for PC files. ENGINE-CONNECTION-OPTIONS
18
Copyright 2009 ENGINE-CONNECTION-OPTIONS Expanded Syntax
19
Copyright 2009 LIBNAME-OPTIONS LIBNAME Option General Syntax ACCESS=- Sets READ ONLY mode DBGEN_NAME=- Specifies how data source column names are created DBMAX_TEXT=- Specifies maximum character string size DBSASLABEL=- Select if Excel Column names are uses as SAS labels DEFER=- Define if the Excel file is opened upon Definition or use DIRECT_SQL=- Define what SQL SAS will send Microsoft Jet/Engine SCAN_TEXTSIZE=- Scan Excel Text columns for the longest variable size SCAN_TIMETYPE=- Determine the type of date/time formats to use STRINGDATES=- Define if date and time values are strings or numeric USE_DATETYPE= - Determine if DATE or DATETIME informats are used LIBNAME xls_data EXCEL ‘C:\WUSS_2009\My_Excel_File.xls’ OPTION=Value;
20
Copyright 2009 DATASET-OPTIONS DATASET Option General Syntax PROC PRINT DATA=libref.SAS-data-set-name (OPTION-NAME=option-value); Run; Or DATA libref.SAS-data-set-name (OPTION-NAME=option-value); Set libref.SAS-data-set-name (OPTION-NAME=option-value); Run; Dataset Options can be used Wherever and With standard Dataset Options
21
Copyright 2009 DATASET-OPTIONS DATASET Option General Syntax AUTOCOMMIT=DBCOMMIT= DBCONDITION=DBCREATE_TABLE_OPTS= DBENCODING=DBFORCE= DBGEN_NAME=DBKEY= DBLABEL=DBMAX_TEXT= DBSASLABEL=DBSASTYPE= DBTYPE=INSERT_SQL= READBUFF=SASDATEFMT= Also the Standard DATASET options: DROP=, CNTLLEV=, FIRSTOBS=, IN=, KEEP=, RENAME=, and WHERE= Dataset Options can be used Wherever and With standard Dataset Options
22
Copyright 2009 EXAMPLES Example 1 – Date Processing SAS Default date, SAS Datetime21.2, and SAS Time8. Formats
23
Copyright 2009 EXAMPLES Example 2 – Date Processing SAS Default date, SAS numeric field, and SAS character field
24
Copyright 2009 EXAMPLES Example 3 – Using Standard and Excel Options Complex WHERE= clause, DROP= clause, and Excel options too
25
Copyright 2009 EXAMPLES EXAMPLE 4 – Reading BOTH Character & numeric data Two SAS programs reading the same file and getting different results v
26
Copyright 2009 Leave Your Bad Code Behind: 50 Ways to Make Your SAS® Code Execute More Efficiently. QUESTIONS???? William E Benjamin Jr Owl Computer Consultancy, LLC
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.