File-Specific Reference |
LIBNAME Statement |
By default, the SAS LIBNAME statement connects to a Microsoft Excel file in limited READ/WRITE mode. Although you can read data, delete a table, or create a new table, you cannot update data or append a new data row. To allow data update and append, set the LIBNAME option SCANTEXT=NO.
Because the SAS PROC SQL pass-through connects to a Microsoft Excel file in READ/WRITE mode. You can read, write, and update data by passing SQL command statements.
Connection Options |
You can use this connection option in the LIBNAME statement or in the PROC SQL CONNECT statement.
determines whether the first row of data in a Microsoft Excel range (or spreadsheet) are column names.
YES |
specifies to use the first row of data in an Excel range (or spreadsheet) as column names. |
NO |
specifies not to use the first row of data as column names in an Excel range (or spreadsheet). SAS generates and uses the variable names F1, F2, F3, and so on. |
Alias: | HDR|GETNAMES |
Default: | YES |
Note: | This connection option is only for reading Microsoft Excel spreadsheets. This option is ignored when you are writing data to an Excel spreadsheet. |
specifies whether to convert numeric data values into character data values for a column of mixed data types. This option is valid only when importing (reading) data from Excel. The Microsoft Ace and Jet Excel engines handle this option.
assigns a SAS character type for the column and converts all numeric data values to character data values when mixed data types are found. When you specify MIXED=YES, the connection is set in import mode and no updates are allowed.
assigns numeric or character type for the column, depending on the majority of the type data that is found. Both numeric data in a character column and character data in a numeric column are imported as missing values.
Default: | NO |
Restriction: | DBMS= only |
Restriction: | This option is available only for Windows reading Excel data into SAS. You cannot use this option for delimited files. |
Restriction: | Registry settings might affect the behavior of the MIXED= option. |
For the Microsoft Jet engine, these settings are located in the [\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel] key of the Windows registry.
For the Microsoft Ace engine, these settings are located in the [\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Acces Connectivity Engine] key of the Windows registry.
TypeGuessRows |
An integer type with a default value of 8. You can use the number of
rows in the worksheet range in scans to determine column types. If you set
this type to 0, all rows in the range are checked. Microsoft states that the
valid range of TypeGuessRows is 0-16. However, you could set as high
as 16384 and it would still operate correctly.
|
ImportMixedTypes |
A string type with a default value of Text. While scanning TypeGuessRows
rows, if a column has multiple data types, the column type is Text. This is
only if the value of the setting is Text. If the value of the setting is Majority,
the most common data type in the column is set as the column type.
For the MIXED=YES option to work correctly, you should you change TypeGuessingRows to 0 in the Microsoft Windows registry so that all rows in the specified range are scanned. As a result, when you use MIXED=YES, the Jet provider always assigns character type for columns with data of mixed data types and converts numeric data to character data. |
TypeGuessRows |
an integer type with a default value of 8. The number of rows in the worksheet range is used to scan and determine column types. If set to 0, then all rows in the range are checked. Microsoft states that the valid range of TypeGuessRows is 0 to 16. However, it can be set as high as 16,384 and still operate correctly. |
ImportMixedTypes |
a string type with a default value of Text. If a column contains more than one type of data (during the scan of TypeGuessRows rows), the column type is Text if the value is Text. If the value is Majority, the most common type determines the column type. |
Note: | For the MIXED=YES option to work correctly, change TypeGuessingRows to 0 in the Windows registry. All rows in the specified range are scanned. Now when you use MIXED=YES, the Jet provider always assigns character type for columns with mixed data types. It also converts numeric data to character data. |
specifies the version of the file that you want to create if the file does not exist. Valid values are 2003, 2002, 2000, 97, 95, and 5. The default value is 97.
Alias: | VER |
Note: | You do not need to specify this option if you do not know the version of your Microsoft Excel file. However, if you want to create a new Microsoft Excel file, you can use this option to specify the version that you create. There is no need to specify the VERSION= value if you want to create a 2007 Excel .xlsb or .xlsx file. The file extension tells SAS the VERSION= value. |
Note: | Versions 2003, 2002, 2000, and 97 are treated as the same format. Versions 95 and 5 share the same format. |
Data Types Conversion |
This table shows the default SAS variable formats that SAS/ACCESS assigns to Excel data types. The data formats are assigned when SAS reads data from Microsoft Excel spreadsheets using the LIBNAME engine.
Excel Column
Format |
SAS Variable
Format |
SAS Variable
Type |
---|---|---|
Text | $w. | Character |
General |
|
Numeric |
Number |
|
Numeric |
Scientific |
|
Numeric |
Percentage | See Note 3 | Numeric |
Fraction | See Note 3 | Numeric |
Currency | DOLLAR21.2 | Numeric |
Accounting | DOLLAR21.2 | Numeric |
Date | DATE9. See Note 12 | Numeric |
Time | TIME8.12 | Numeric |
1
The default format is DATE9. You can use USEDATE=NO to change format
from DATE9. to DATETIME. You can also use the SASDATEFMT= option to change
the format of other SAS date and time formats.
2 Note that the SAS date time value uses 01Jan1960 as a cutoff line, while the Jet provider date value uses 30Dec1899 as a cutoff line for internal values. 3 To access Fraction or Percent format data in your Excel file, you can use the FORMAT statement to assign the FRACT. or PERCENT. format in your DATA step code. |
The following table shows the default Excel data types that SAS/ACCESS assigns to SAS variable formats. These data types are assigned when SAS writes data to an Excel file using the LIBNAME engine. You can override these default conversions by using DBTYPE during output processing.
SAS Variable
Format |
XLS Column
Data Type |
---|---|
$BINARYw. |
Text |
$CHARw. | Text |
$HEX w. |
Text |
$w. | Text |
w.d | Number |
BESTw. |
Number |
BINARYw. | Number |
COMMA w.d |
Number |
COMMAXw.d |
Number |
Ew. |
Number |
FRACTw. |
Number |
HEXw. |
Number |
NEGPARENw.d |
Number |
PERCENTw.d |
Number |
DOLLARw.d |
Currency |
DOLLARXw.d |
Currency |
DATEw. |
Date |
DATETIMEw.d |
Date |
DDMMYYw. |
Date |
HHMMw.d |
Time |
JULDAYw. |
Date |
JULIANw. |
Date |
MMDDYYw. |
Date |
MMYYw.d |
Date |
MONTHw. |
Date |
MOYYw. |
Date |
WEEKDATEw. |
Date |
WEEKDATXw. |
Date |
WEEKDAYw. |
Date |
WORDDATEw. |
Date |
WORDDATXw. | Date |
Processing Date and Time Values between SAS and Microsoft Excel |
To import date or time values from a Microsoft Excel file, the SAS LIBNAME engine reads date values using DATE9. by default. Time values are assigned the TIME8. format. However, you can set the LIBNAME option, USEDATE=NO, or the LIBNAME statement, USEDATE=NO. Using the IMPORT procedure, you can have date and time values read in using the DATETIME. format.
To export SAS values with DATE, TIME, or DATETIME formats to a Microsoft Excel file, values are written using DATE9. format. When you see values with the date 1/0/1900 in Microsoft Excel, format them using the TIME format to display the correct time values.
TIME_VAL: By default, the SAS/ACCESS LIBNAME engine loads the SAS time value in the ACCESS database. The time value is set to less than or equal to 24 hours. Set the time environment variables follows:
OPTIONS SET=TIME_VAL SAS:
To load SAS time values with the SAS date and time base of 01Jan1960:00:00:00, enable the time value to be reserved for longer than one day. When you import data with SCANTIME=YES, SAS scans date and time values in the column and assigns the TIME8. format if all the values in the column are in the year 1960. If this is not the case, SAS assigns the DATETIME format for the column. You can reset the TIME_VAL back to the default value with the following code:
OPTIONS SET=TIME_VAL_ONEDAY;
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.