Sas/Access 9.3 Interface To PC Files: Reference
Sas/Access 9.3 Interface To PC Files: Reference
3 Interface
®
to PC Files
Reference
SAS® Documentation
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2011. SAS/ACCESS® 9.3 Interface to Files: Reference. Cary,
NC: SAS Institute Inc.
SAS/ACCESS ® 9.3 Interface to PC Files: Reference
Copyright © 2011, SAS Institute Inc., Cary, NC, USA
All rights reserved. Produced in the United States of America.
For a hardcopy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc.
For a Web download or e-book:Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this
publication.
The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and
punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted
materials. Your support of others' rights is appreciated.
U.S. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the U.S. government is
subject to the Agreement with SAS Institute and the restrictions set forth in FAR 52.227–19 Commercial Computer Software-Restricted Rights
(June 1987).
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.
1st electronic book, July 2011
SAS ® Publishing provides a complete selection of books and electronic products to help customers use SAS software to its fullest potential. For
more information about our e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site at
support.sas.com/publishing or call 1-800-727-3228.
SAS ® and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other
countries. ® indicates USA registration.
Other brand and product names are registered trademarks or trademarks of their respective companies.
Contents
Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures . . . . . . 27
Delimited Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Microsoft Excel Workbook Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Microsoft Access Database Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Lotus 1-2-3 WKn Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
dBase DBF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
dBase DBF MEMO Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
JMP Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Paradox DB File Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
SPSS SAV Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Stata DTA Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
iv Contents
Chapter 9 • The LIBNAME Statement for Access and Excel on Microsoft Windows . . . . . . . . . 97
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows . . . . . . . . . 129
Pass-Through Facility on Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Chapter 13 • File-Specific Reference for Access and Excel on Microsoft Windows . . . . . . . . 147
Microsoft Excel Workbook Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Microsoft Access Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Chapter 16 • Pass-Through Facility: PCFILES on Linux, UNIX, and Microsoft Windows . . . . 205
Overview: Pass-Through Facility for PCFILES on Linux, UNIX,
and Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .205
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206
Chapter 20 • File-Specific Reference for the ACCESS and DBLOAD Procedures . . . . . . . . . . 259
Overview: ACCESS Procedure and DBLOAD Procedure . . . . . . . . . . . . . . . . . . . . . 260
ACCESS Procedure: XLS Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
DBLOAD Procedure: XLS Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .266
ACCESS Procedure: WKn Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
DBLOAD Procedure: WKn Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
ACCESS Procedure: DBF Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
DBLOAD Procedure: DBF Specifics (Windows) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
ACCESS Procedure: DIF Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
DBLOAD Procedure: DIF Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .301
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
vi Contents
vii
Audience
This document is intended for applications programmers and users who know how to use
their operating environment, PC files, and basic SAS commands and statements. This
document provides a general reference, as well as specific details, and SAS code
examples that show how to access and use data in PC files directly from within SAS.
viii Using This Document
ix
Overview
SAS/ACCESS 9.3 Interface to PC Files enables you to exchange (import and export) PC
files between the original source format and SAS data sets. Files are moved between the
native PC format and SAS data sets via Import and Export procedures and wizards or
through the use of LIBNAME statements.
General Enhancements
LIBNAME Engines
Starting in SAS 9.3, SAS/ACCESS 9.3 Interface to PC Files supports these LIBNAME
engines:
• LIBNAME ACCESS engine for 32- and 64-bit Microsoft Windows operating
systems
• LIBNAME EXCEL engine for 32- and 64-bit Microsoft Windows operating systems
• LIBNAME PCFILES engine for 32- and 64-bit Microsoft Windows operating
system and for Linux and UNIX operating systems
x SAS/ACCESS 9.3 Interface to PC Files
• LIBNAME JMP engine for Linux, UNIX, and Microsoft Windows operating
systems
• In this release, the Import procedure supports source type XLSX to read the
Microsoft Excel 2007 and 2010 default file format (.xlsx) on Linux, UNIX, and
Microsoft Windows operating systems.
• Import and Export procedures and wizards support the following source types in
both 32- and 64-bit Microsoft Windows operating system.
• Microsoft Access database files (*.accdb, *.mdb)
• Microsoft Excel files (workbook: *.xlsx, *.xlsm, *.xlsb; spreadsheet: *.xls)
• Microsoft Access database on PC Files Server
• Microsoft Excel workbook on PC Files Server
PC Files Server
Beginning with SAS/ACCESS 9.3 Interface to PC Files, the PC Files Server can be
operated as a Windows service or as a Windows application on the 64-bit Windows
operating system. This allows the server to take advantage of the associated 64-bit
features and to operate more efficiently. The PC Files Server continues to operate on and
support the Windows 32-bit operating system.
xi
Recommended Reading
Part 1
Chapter 1
Working with SAS/ACCESS 9.3 Interface to PC Files . . . . . . . . . . . . . . . 3
2
3
Chapter 1
Working with SAS/ACCESS 9.3
Interface to PC Files
Part 2
Chapter 2
Supported Data Sources and Environments . . . . . . . . . . . . . . . . . . . . . . . 7
Chapter 3
Using the SAS Import and Export Wizards . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 4
The IMPORT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Chapter 5
The EXPORT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Chapter 6
File Format-Specific Reference for the IMPORT and EXPORT
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6
7
Chapter 2
Supported Data Sources and
Environments
Reading and Writing Data between SAS Data Sets and PC Files . . . . . . . . . . . . . . . 7
Supported Data Sources and Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
engine
1
Data Source Identifier EXCEL has alias names EXCEL2007 and EXCEL2010.
2
Data Source Identifier EXCEL97 has alias names EXCEL2000, EXCEL2002, and EXCEL2003.
3
Data Source Identifier ACCESS has alias names ACCESS2007 and ACCESS2010.
4
Data Source Identifier ACCESS2000 has alias names ACCESS2002 and ACCESS2003.
5
Yes for Microsoft Windows, for SAS 9.2 Phase 3 up to and excluding this release.
10 Chapter 2 • Supported Data Sources and Environments
11
Chapter 3
Using the SAS Import and Export
Wizards
From the Import Wizard or from the Export Wizard, if you select User-defined format
from the data source selection window, after a series of windows that request specific
information, the Import or Export Wizard prompts you to select Finish to invoke the
EFI.
Note: To return to the Import or Export Wizard without invoking the EFI, select Back.
To close the Import or Export Wizard without invoking the EFI, select Cancel.
For instructions about using the EFI, select Help ð Using This Window.
13
Chapter 4
The IMPORT Procedure
To import data, you can use the Import Wizard. This windowing tool guides you through
the steps to import an external data source. You can request that the Import Wizard
generate IMPORT procedure statements. You can save these statements for subsequent
use. To open the Import Wizard, select File ð Import Data from the SAS windowing
environment.
Syntax
PROC IMPORT
DATAFILE= <'filename'> | DATATABLE= <'tablename'> (Not used for Microsoft Excel files)
<DBMS>= <data-source-identifier>
<OUT>= <libref.SAS data-set-name> <SAS data-set-option(s)>
<REPLACE>;
<file-format-specific-statements>
Required Arguments
DATAFILE=filename
specifies the complete path and filename or fileref for the input file. A fileref is a
SAS name that is associated with the physical location of the output file. To assign a
fileref, use the FILENAME= statement. You can omit the quotation marks if the
filename does not include certain characters such as these:
• backslash
• lowercase characters
• spaces
Alias: FILE
Default: character
Restrictions:
The IMPORT procedure does not support device types or access methods for the
FILENAME statement except for DISK. For example, the IMPORT procedure
does not support the TEMP device type, which creates a temporary external file.
When runningSAS/ACCESS on UNIX, to access data stored on a PC server,
specify the full path and filename of the import file. The use of a fileref is not
supported.
The IMPORT procedure can import data if the data type is supported by SAS.
SAS supports numeric and character types of data but not (for example, binary
objects). If the data that you want to import is a type that SAS does not support,
the IMPORT procedure might not import it correctly. In many cases, the
PROC IMPORT Statement 15
procedure attempts to convert the data to the best of its ability. However, at times
this is not possible.
Interaction: For some input data sources such as a Microsoft Excel workbook, the
first eight rows of data are scanned. The most prevalent data type (numeric or
character) is used for a column. This is the default. If most of the data in the first
eight rows is missing, SAS defaults to data type (character) and any subsequent
numeric data for that column is set to missing.
Notes:
For information about how SAS converts data types, see the specific information
for the data source file format that you are importing.
To import DBF files created with Microsoft Visual FoxPro, you must export to
an appropriate dBASE format using Visual FoxPro. Import the dBASE file to
SAS.
See: The FILENAME statement in SAS Statements: Reference.
DATATABLE= 'table-name'
specifies the table name of the input DBMS table. If the name does not include
special characters, such as question marks, lowercase characters, or spaces, you can
omit the quotation marks. The DBMS table name might be case sensitive and is
generally used for MSACCESS tables, but not for Microsoft Excel sheets.
Alias: TABLE
Requirements:
When importing Microsoft Access tables,SAS/ACCESS converts the table name
to a SAS member name. SAS does not support member names longer than 32
bytes.
When you import a DBMS table, you must specify the DBMS= option.
Optional Arguments
SAS data-set-option(s)
Specify SAS data set options. For example, to assign a password to the resulting
SAS data set, you can use the ALTER= , PW= , READ= , or WRITE= data set
options. To import only data that meets a specified condition, you can use the
WHERE data set option. For information about all SAS data set options, see SAS
Data Set Options: Reference.
DBMS= data-source-identifier
specifies the type of data to import. To import a DBMS table, specify DBMS= using
a supported database identifier listed in Table 4.1 on page 15. For example,
DBMS=ACCESS specifies to import a Microsoft Access 2000, 2002, 2003, or 2007
database. All DBMS= specifications refer to local access, except where noted in this
table.
Note: Transcoding is not supported for DBMS=XLS. Attempted execution of this
operation yields unpredictable results. As an alternative, use DBMS=EXCEL or
DBMS=EXCELCS with PC Files Server.
Table 4.1 DBMS Specifications
Data Source
Identifier Output Data Source File Extension
Data Source
Identifier Output Data Source File Extension
DBFMEMO dBASE 5.0, IV, III+, and III files with memos FoxPro .dbf
and Visual FoxPro files with memos
.fpt
.dbt
EXCEL4 Microsoft Excel 4.0, Excel 5.0 or 7.0 (95) workbook. .xls
EXCEL5
PCFS JMP files, SPSS files, and Stata files connecting .jmp, .sav, .dta
remotely through PC Files Server.
XLS Microsoft Excel 5.0, 95, 97, 2000, 2002, or 2003 .xls
workbook using file formats
PROC IMPORT Statement 17
Data Source
Identifier Output Data Source File Extension
Note: All DBMS= specifications refer to local access, except for these
specifications:
• DBMS=ACCESSCS
• DBMS=EXCELCS
• DBMS=PCFS
These files are accessed remotely by connecting to PC Files Server on Microsoft
Windows.
Microsoft Excel
When you specify DBMS=XLS or DBMS=XLSX for an Excel file, you can read
and write to Excel workbooks under UNIX directly without having to access the
PC Files Server. The following example demonstrates the use of DBMS=XLSX
specifying a range of cells.
Microsoft Excel 97, 2000, 2002, and 2003 share the same internal file formats.
The SAS LIBNAME engine recognizes EXCEL97, EXCEL2000, EXCEL2002,
EXCEL2003, EXCEL2007, and EXCEL2010 as aliases for the identifier
EXCEL. By specifying DBMS=EXCEL, the IMPORT procedure can read any
version of these files that are saved in Microsoft Excel workbooks.
Table 4.2 Microsoft Excel Workbook Specifications
Excel 97,
Excel 2007, 2000, 2002,
Identifier 2010 2003 Excel 5.0, 95 Excel 4.0
XLSX Yes No No No
Operating
DBMS Uses Requires Platform
PCFS
Specify DBMS=PCFS for JMP, SPSS, and Stata files to use the client/server
model. This enables you to access data on Microsoft Windows from Linux,
UNIX, or other Microsoft Windows operating environments. These files are
accessed remotely by connecting to a PC Files Server on Microsoft Windows.
Microsoft Access
Microsoft Access versions 2000, 2002, and 2003 share the same internal file
formats. The SAS LIBNAME engine recognizes ACCESS2000, ACCESS2002,
ACCESS2003, ACCESS2007, and ACCESS2010 as aliases for the identifier
ACCESS. By specifying DBMS=ACCESS, SAS can read any of these versions
of files that are saved in Microsoft Access applications.
To import a SAS data from an existing Microsoft Access database, the IMPORT
procedure can read existing Access 97, Access 2000, Access 2002, or Access
2003 database files. If you specify DBMS=ACCESS2000 and the database is in
Access 97 format, the IMPORT procedure imports the table, and the database
remains in Access 97 format.
When the DATABASE= option is specified for an Access database .mdb file that
does not exist, a database is created using the format specified in the DBMS=
option. If you specify DBMS=ACCESS to create a file, the result is an MDB file
that Access 2000, 2002, and 2003 can read. Access 97 cannot read this file.
For more information about the DATABASE= option, see “Microsoft Access
Database Files ” on page 52.
Access 2007 can open all formats. Only Access 2007 and later can open Access 2007
file formats.
Table 4.4 Access Table Specifications
OUT=libref.SAS data-set
identifies the output SAS data set with either a one- or two-level SAS name (library
and member name). If the specified SAS data set does not exist, The IMPORT
procedure creates it. If you specify a one-level name, by default the IMPORT
procedure uses either the SASUSER library if assigned or the WORK library if
SASUSER not assigned.
REPLACE
overwrites an existing SAS data set. If you do not specify REPLACE, the IMPORT
procedure does not overwrite an existing file.
<file-format-specific-statements>
see “File Format-Specific Reference for the IMPORT and EXPORT Procedures”
on page 29 for the supported syntax for your DBMS.
20 Chapter 4 • The IMPORT Procedure
21
Chapter 5
The EXPORT Procedure
To export data, you can use the Export Wizard, which is a windowing tool that guides
you through the steps to export to an external data source. You can request that the
Export Wizard generate EXPORT procedure statements, which you can save for
subsequent use. To open the Export Wizard, select File ð Export Data from the SAS
windowing environment.
Syntax
PROC EXPORT DATA=<libref.>SAS data set <(SAS data set options)>
OUTFILE="filename" | OUTTABLE="tablename"
<DBMS=identifier> <REPLACE> <LABEL>;
<file-format-specific-statements>
Required Arguments
DATA=<libref.> SAS data set
specifies the input SAS data set with either a one- or two-level SAS name (library
and member name). If you specify a one-level name, by default, the EXPORT
procedure uses either the SASUSER library (if assigned) or the WORK library (if
SAS system option USER is not assigned).
Default: If you do not specify a SAS data set, the EXPORT procedure uses the most
recently created SAS data set. SAS keeps track of data set order with the system
variable _LAST_. To ensure that the EXPORT procedure uses the correct data
set, identify the SAS data set with a two-level name.
Restriction: The EXPORT procedure can export data if the data format is supported
and the amount of data is within the limitations of the data source. Some data
sources have a maximum number of rows or columns. If the data that you want
to export exceeds the limits of the data source, the EXPORT procedure might not
be able to export it correctly. When SAS encounters incompatible formats, the
procedure formats the data to the best of its ability.
OUTFILE= filename
specifies the complete path and filename, or a fileref for the output PC file,
spreadsheet, or delimited external file. If the name does not include special
characters (such as question marks), lowercase characters, or spaces, omit the
quotation marks.
Alias: FILE
Restrictions:
The EXPORT procedure does not support device types or access methods for the
FILENAME statement except for DISK. For example, the EXPORT procedure
does not support the TEMP device type, which creates a temporary external file.
PROC EXPORT Statement 23
For client/server applications: Specify the full path and filename of the import
file when you are runningSAS/ACCESS software on UNIX to access data that is
stored on a PC server. Use of a fileref is not supported.
OUTTABLE= table-name
specifies the DBMS output table. If the name does not include special characters
(such as question marks), lowercase characters, or spaces, omit the quotation marks.
The DBMS table name might be case sensitive.
Alias: TABLE
Restriction: Used for only MSACCESS files.
Note: For PC files the table name is generally used for Microsoft Access databases.
Optional Arguments
<SAS data-set-option(s)>
specifies SAS data set options. For example, if the data set that you are exporting has
an assigned password, you can use the ALTER= option, the PW= option, the READ
= option, or the WRITE= option. To export only data that meets a specified
condition, you can use the WHERE= data set option. For information about SAS
data set options, see “Data Set Options” in SAS Language Reference: Dictionary.
DBMS= data-source-identifier
DBMS= specifies the type of external data source the EXPORT procedure creates.
To export to a DBMS table, specify DBMS= using a supported database identifier.
For example, DBMS=ACCESS specifies to export a table into a Microsoft Access
2000, 2002, 2003, or 2007 database.
Note: Transcoding is not supported for DBMS=XLS. The output yields
unpredictable results. Use DBMS=EXCEL as an alternative.
Table 5.1 Data Source Identifier Summary
ACCESS Microsoft Access 2000, 2002, 2003, 2007, or 2010 table .mdb
(using the LIBNAME statement)
.accdb
DBFMEMO dBASE 5.0, IV, III+, and III files with memos .dbf
FoxPro and VisualPro with memos .fpt
EXCEL Excel 97, 2000, 2002, 2003, 2007 or 2010 workbook .xls
(using the LIBNAME statement)
.xlsb
.xlsx
24 Chapter 5 • The EXPORT Procedure
EXCEL5 Excel 5.0 or 7.0 (95) workbook (using PROC DBLOAD) .xls
PCFS JMP files, Stata files, and SPSS files connecting .jmp, .dta, .s
remotely through PC FIles Server av
XLS Excel 97, 2000, 2002, or 2003 spreadsheet (using file .xls
formats)
Note: Transcoding is not supported for DBMS=XLS.
The output yields unpredictable results. Use
DBMS=EXCEL as an alternative.
When you specify a value for DBMS=, consider the following for specific data
sources:
• When you specify DBMS=XLS for an Excel file, you can read and write to Excel
workbooks under Microsoft Windows and UNIX directly without having to
access the PC Files Server.
• Specify DBMS=PCFS for JMP, SPSS, and Stata files to use the client/server
model. This enables you to access data on Microsoft Windows from Linux,
UNIX, or Microsoft Windows 64-bit operating environments. These files are
accessed remotely by connecting to a PC Files Server on Microsoft Windows.
• Microsoft Access versions 2000, 2002, and 2003 share the same internal file
formats. The SAS LIBNAME engine recognizes ACCESS 2000, ACCESS 2002,
ACCESS 2003, ACCESS 2007, and ACCESS 2010 as aliases for the identifier
ACCESS. By specifying DBMS=ACCESS, the SAS export file can be read by
any of these versions of files that are saved in Microsoft Access applications.
• Microsoft Excel 97, 2000, 2002, and 2003 share the same internal file formats.
The SAS LIBNAME engine recognizes EXCEL97, 2000, 2002, 2003, and
EXCEL2007 as aliases for the identifier EXCEL. By specifying DBMS=EXCEL,
the SAS export file can read any of these versions of files that are saved in
Microsoft Excel workbooks.
PROC EXPORT Statement 25
• To export a SAS data set to an existing Microsoft Access database, the EXPORT
procedure can write to existing Access 97, Access 2000, Access 2002, or Access
2003 database files. If you specify DBMS=ACCESS2000 and the database is in
Access 97 format, the EXPORT procedure exports the table, and the database
remains in Access 97 format.
When the DATABASE= option is specified for an Access database .mdb file that
does not exist, a database is created using the format specified in the DBMS=
option. If you specify DBMS=ACCESS to create a file, the result is an MDB file
that Access 2000, 2002, and 2003 can read. Access 97 cannot read this file.
For more information about the DATABASE= option, see “Microsoft Access
Database Files ” on page 52.
The files created by SAS can be opened and read by various Microsoft Access
versions, as indicated in the following table.
Table 5.2 Exported Data: Microsoft Access Readability
ACCESS 2007
Note: Only Access 2007 and later can open Access 2007 file formats.
• To export a Microsoft Excel spreadsheet, the EXPORT procedure creates an
XLS file for the specified version. When exporting to an existing Excel
workbook .XLS file a .BAK file is created.
The files created by SAS can be opened and read by various Microsoft Excel
versions, as indicated in the following table.
Table 5.3 Exported Data: Microsoft Excel Workbook Readability
• Missing values are translated to blanks when you export a SAS data set to a
dBASE file (DBF).
• Due to dBASE limitations, character variable values longer than 256 characters
are truncated in the resulting dBASE file.
Restrictions:
The availability of an output data source depends on:
Only Excel 2007 and later can open Excel 2007 formats.
26 Chapter 5 • The EXPORT Procedure
Note: All DBMS= specifications refer to local access, except for: These files are
accessed remotely by connecting to PC Files Server on Microsoft Windows.
See: “File Format-Specific Reference for the IMPORT and EXPORT Procedures”
on page 29
LABEL
writes SAS label names as column names to the exported table. If SAS label names
do not exist, then the variable names are used as column names in the exported table.
Alias: DBLABEL
REPLACE
overwrites an existing file. For a Microsoft Access database or an Excel workbook,
REPLACE overwrites the target table or spreadsheet. If you do not specify
REPLACE, the EXPORT procedure does not overwrite an existing file.
<file-format-specific-statements>
see “File Format-Specific Reference for the IMPORT and EXPORT Procedures”
on page 29 for the supported syntax for your DBMS.
27
Chapter 6
File Format-Specific Reference
for the IMPORT and EXPORT
Procedures
Delimited Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CSV Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Tab-Delimited Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Other Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
External File Interface (EFI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
IMPORT and EXPORT Procedure Statements for Delimited Files . . . . . . . . . . . . . 30
Example 1: Import a Tab-Delimited File into SAS . . . . . . . . . . . . . . . . . . . . . . . . . 32
Example 2: Import a Space-Delimited File into SAS . . . . . . . . . . . . . . . . . . . . . . . . 32
Example 3: Export a SAS Data Set to a CSV File . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Example 4: Import a Subset of a CSV File into SAS . . . . . . . . . . . . . . . . . . . . . . . . 32
Microsoft Excel Workbook Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Microsoft Excel Files Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Excel Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Excel Numeric Data and Time Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Excel File Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
SAS Import and Export Utilities Support for Excel Files . . . . . . . . . . . . . . . . . . . . 35
Importing and Exporting Microsoft Excel 4 and Excel 5 Files . . . . . . . . . . . . . . . . 46
Example 1: Import a SAS Data Set to an Excel 5 File . . . . . . . . . . . . . . . . . . . . . . . 48
Example 2: Export a SAS Data Set to an Excel 5 File . . . . . . . . . . . . . . . . . . . . . . . 48
Import and Export Microsoft Excel Files Using XLS and XLSX File Formats . . . 48
Example 1: Export SAS Data Sets to Excel Workbook Files . . . . . . . . . . . . . . . . . 51
Example 2: Import Data Using a Range Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Example 3: Import Data Using an Absolute Range Address . . . . . . . . . . . . . . . . . . 52
Microsoft Access Database Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Microsoft Access File Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Microsoft Access Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The Conversion of Date and Time Values between SAS Data
Sets and Microsoft Access Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
IMPORT and EXPORT Procedure Statements for Access Files . . . . . . . . . . . . . . . 54
Lotus 1-2-3 WKn Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
WKn Files Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
WKn Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Supported Import and Export Methods and Statements for WKn Files . . . . . . . . . . 63
Example 1: Export a SAS Data Set to a WK4 File . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Example 2: Import Data from a SAS Data Set from a WK4 File . . . . . . . . . . . . . . . 65
Example 3: Export Data to a WK1 File from a SAS Data Set . . . . . . . . . . . . . . . . . 65
Example 4: Import Data from a WK1 File into a SAS Data Set . . . . . . . . . . . . . . . 66
dBase DBF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
28 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Delimited Files
Overview
In computer programming, a delimited text file is a file in which the individual data
values contain embedded delimiters, such as quotation marks, commas, and tabs. A
delimiter is a character that separates words or phrases in a text string that defines the
beginning or end of a contiguous string of character data.
• The delimiter is not considered part of the character data string.
• The first row of data is usually read as column headings.
• The column headings are then converted to SAS variable names.
• A line character indicates a new row.
A delimited text file is also called a delimiter-separated values file (CSV or DSM).
Note: Support of delimited files is included in Base SAS. The SAS/ACCESS to PC
Files license is not needed to use this list of features.
CSV Files
A comma-separated values file is a form of a delimited file. The data values are
separated by commas. In a CSV-type file, each line can represent one of these items:
• an entry
• a record
• a row
• an observation in a database management system
• other applications
Tab-Delimited Files
A tab-delimited file is a form of delimited file. The data values are separated by control
characters that represent the TAB key. The data values form columns of a database table.
The columns can be exported to a database table.
Other Delimiters
Files that have other delimiters such as spaces or semicolons are also known as delimited
text files or delimited files.
• When data values are enclosed in quotation marks, delimiters within the value are
treated as character data.
• Quotation marks are removed from character values.
• Two consecutive delimiters indicate a missing value.
• A delimiter can be specified as one or more characters.
• While exporting data, the EXPORT procedure discards items that exceed the output
line length. See the DROPOVER= option in the FILE statement in SAS Statements:
Reference.
• The delimiter can be in binary form. For example: delimiter='09'X
• As the IMPORT procedure reaches the end of the current input data row, variables
without any values are set to missing.
See Also
• “Using the SAS Import and Export Wizards” on page 11
• Chapter 4, “The IMPORT Procedure,” on page 13
DATAROW= n
specifies the row number where the IMPORT procedure starts reading data.
Default: When GETNAMES=NO: 1; when GETNAMES=YES: 2
Range: 1 to 2147483647
Restrictions:
If GETNAMES = Yes, then DATAROW must be greater than or equal to 2.
If GETNAMES = No, then DATAROW must be greater than or equal to 1.
DELIMITER= 'char' | 'nn'x
specifies the delimiter (either a single character or hexadecimal value) that separates
the columns of data for the IMPORT and EXPORT procedures.
Default: A blank character
Restriction: Support only for DLM type files.
GETNAMES= YES | NO
specifies whether the IMPORT procedure is to generate SAS variable names from
the data values in the first row of the import file. If a data value in the first record
contains special characters that are not valid in a SAS name, SAS converts the
character to an underscore. For example, The column name Occupancy Code
becomes the SAS variable name Occupancy_Code.
YES specifies that the IMPORT procedure generate SAS variable names from the
data values in the first row of the imported Excel file.
NO specifies that the IMPORT procedure generate SAS variable names as F1, F2,
F3, and so on.
Default: Yes
Restriction: Valid only for the IMPORT procedure.
GUESSINGROWS= n
specifies the number of rows that the IMPORT procedure is to scan to determine the
appropriate data type for the columns. The scan process scans from row 1 to the row
number that is specified by GUESSINGROWS = option.
The default row number can be changed in the SAS REGISTRY as follows: From
the SAS menu, Solutions ð Accessories ð Registry Editor.
When the Registry Editor opens, select Products ð BASE ð EFI ð
GuessingRows. This opens the Edit Signed Integer Value window, where you can
modify the Value Data item.
Default: 20
Range: 1 to 2147483647
PUTNAMES= YES | NO
YES specifies that the EXPORT procedure is to do the following tasks:
• Write the SAS variable names to the first row of the exported data file as column
headings.
• Write the first row of the SAS data set to the second row of the exported data
file.
NO specifies that the EXPORT procedure is to write the first row of SAS data set
values to the first row of the exported data file.
Default: Yes
Restriction: Valid only for the EXPORT procedure.
Note: If you specify the LABEL= option, the SAS variable labels (not the variable
names) are written as column headings.
32 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
GETNAMES=YES;
DATAROW=6;
RUN;
OPTIONS OBS=MAX;
Overview
SAS Import and Export Utilities provide three methods to access Microsoft Excel files.
LIBNAME statement
generates a LIBNAME statement and SQL commands for the PC files engine. Read
data from or write data to an Excel file. This method supports Excel versions 5, 95,
97, 2000, 2002, 2003, and 2007.
See “Overview: LIBNAME Engines” on page 89 for additional information.
Note: DBMS=EXCEL and DBMS=EXCELS use this method to access data in
Excel files.
ACCESS and DBLOAD procedures
generate ACCESS procedure code to read data from an Excel file. Also generate the
DBLOAD procedure code to write data to an Excel file. This method supports only
Excel versions 4 and 5/95. This is for SAS 6 compatibility support and is available
only on Microsoft Windows.
Note: DBMS=EXCEL5 uses this method to access data in Excel files.
XLS and XLSX file formats
translates Excel .xls or .xlsx file formats to read data from or write data to an Excel
file. This component supports Excel versions 5/95, 97, 2000, 2002, and 2003.
Note: This method does not support Excel .xlsb files, and it does not support such
DBCS character sets as Chinese, Japanese, or Korean.
Note: DBMS=XLS and DBMS=XLSX use this method to access data in Excel files.
See “SAS/ACCESS Descriptors for PC Files” on page 227.
The next table lists Statement Options to Import or Export Excel Data files on Linux,
Windows, and UNIX. This method requires that the PC Files Server is running on a
Microsoft Windows operating system where the PC files reside.
Microsoft Excel Workbook Files 37
Table 6.3 Statement Options to Import or Export Excel Data Files on Windows, Linux, and
UNIX
DBDSOPTS= valid data set options for the SAS Excel LIBNAME engine
enables data set options for the LIBNAME engine such as READBUFF,
INSERTBUFF, DBTYPE, DROP, FIRSTOBS, and OBS. These options are for
advanced users who are familiar with the PC Files LIBNAME engine.
Notes:
To improve performance for reading data, set the READBUFF= option to 25 or
higher.
Enclose the options in single or double quotation marks as shown in the
examples.
If the option string that you specify contains single quotations marks, use double
quotation marks around it in your statement.
See: “Overview of Data Set Options” on page 103 and “Data Set Options for
PCFILES on Linux, UNIX, and Microsoft Windows” on page 186 for additional
information.
Example: DBDSOPTS Examples
38 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Interaction: The ‘TypeGuessRows’ entry in your registry settings can affect the
behavior of the MIXED= option. The options are located in a key of the
Microsoft Windows registry.
To change the value of ‘TypeGuessRows’ in your registry, follow these steps:
1. Access the Registry Editor by either selecting Start ð Run from your desktop,
entering Regedt and selecting OK, or by following the instructions for your system
found in your system or application documentation.
2. Open the appropriate key in the Registry Editor window, as indicated in the table
below.
Table 6.4 Registry Key for TypeGuessRow Based on Office Version or Engine
Office Version
Environment or Engine Registry Key
Office Version
Environment or Engine Registry Key
The following table describes the registry settings for the MIXED= option.
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 up to 16384 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.
CAUTION: Changing the TypeGuessRows value causes a scan to fail if
you set it higher than 16384. It also affects any software that uses the
Microsoft Ace provider to access Excel file data, including accessing
Excel data in a Microsoft Access database. The TypeGuessRows value is
registered with and controlled by Microsoft. It is recommended that you
set the value to 0.
Microsoft Excel Workbook Files 41
ImportMixedTypes A string type with a default value of Text. If a column contains more than
one type of data while scanning TypeGuessRows rows, the column type
is determined to be Text if the setting value is Text. If the setting value is
Majority Type, the most common column type determines the column
type.
For the MIXED= YES option to work correctly, you should change
TypeGuessRows 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 Microsoft Ace engine and the Microsoft Jet engine always
assign character type for columns with data of mixed data types.
The numeric data is converted to character data.
NEWFILE= YES | NO
when exporting a SAS data set to an existing Excel file, specifies whether to delete
the Excel file, and load the data to a sheet in a new Excel file.
YES specifies that the EXPORT procedure deletes the specified Excel file, if it exists.
Loads the SAS data set to a sheet in a new Excel file.
NO specifies that the EXPORT procedure loads the SAS data set to a sheet and
appends it to the existing Excel file. If the specified Excel file does not exist, an
Excel file is created, and the SAS data set is loaded.
Restriction: Available only when DBMS=EXCEL.
PORT= port-number
specifies the number of the port that is listening on the PC Files Server. The valid
value is between 1 and 65535. This port or service name displays on the PC Files
Server display when the application is started in server mode.
Alias: PORT_NUMBER
Default: 9621
Restrictions:
Available only for the client/server model.
The PORT= statement option and the SERVICE= statement option should not be
used in the same procedure.
RANGE= range-name | absolute-range
subsets a spreadsheet by identifying the rectangular set of cells to import. The range-
name is a user-defined spreadsheet name that represents a range of cells within the
spreadsheet in the Excel file. The range-name is not case sensitive and does not
allow any special character (except an underscore). The range-name is identified by
the top left cell that begins the range and the bottom right cell that ends the range
within the Excel worksheet file. The beginning and ending cells are separated by two
periods. For example, the range address C9..F12 indicates a cell range that begins at
Cell C9, ends at Cell F12, and includes all cells in between. You must define range-
name with a workbook scope so that the name is visible to SAS.
You can use the DATASETS procedure to list the data set names, that are mapped to
the range-names. If the displayed range-name contains single quotes, keep the single
quotes as part of the range-name to access the sheet.
An absolute range identifies the top left cell that begins the range and the bottom
right cell that ends the range.
The following examples demonstrate the use of RANGE=.
• To retrieve data from the spreadsheet for two separate sheet names, 'My#Test'
and 'CustomerOrders':
42 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
RANGE="'My#Test$'";
RANGE="' CustomerOrders$'";
• To represent cells within Column C, Row 2, and Column F, Row 12: C2:F12
the colon separates the values for upper left (UL) and lower right (LR) of the
range. If this statement is not specified, the IMPORT procedure reads the entire
spreadsheet as a range.
• When data is imported from an Excel file, a sheet name that is appended with a $
character is treated as a range name. The range name refers to the whole sheet.
RANGE="'summary$a4:b20'";
• If the range name is available, it is recommended that you use RANGE = option
without the SHEET option for the IMPORT procedure. To use the absolute range
address, it is strongly recommended that you use the full range address with
quotes. For example, specify 'sheet_name$A1:C7'n
Restriction: Supported only for the IMPORT procedure.
SCANTEXT= YES | NO
specifies whether to scan the column to determine the length of the text data for each
data source column. This option applies only to character data type columns.
YES scans the length of text data for a data source column and uses the length of the
longest string of data that it finds as the SAS variable width. If the maximum length
that it finds is greater than the value in the TEXTSIZE = option, the smaller value in
TEXTSIZE = option is applied as the SAS variable width.
NO does not scan the length of text data for a data source column. The column length
returned from the Microsoft Ace or Microsoft Jet engine is used as the SAS variable
width. If the returned column width is greater than what is specified in the
TEXTSIZE option, the smaller value specified in the TEXTSIZE= option is applied
as the SAS variable width.
Note: Specify SCANTEXT= NO when you need to update data in a Microsoft Excel
workbook.
Note: So that the SCANTEXT= YES option works correctly, it is strongly
recommended that you change TypeGuessRows to 0 in the Microsoft Windows
registry. This ensures that all rows in the specified range are scanned. For
registry values, see Table 6.4 on page 39.
Note: To correct truncated text data for DBCS users (including Chinese, Japanese,
and Korean), you can set the environment variable DBE_DBCS to YES. This
doubles the scanned text data length and therefore corrects the problem of
truncated text data. To set the DBE_DBCS environment variable, submit this
statement: Options set=DBE_DBCS YES;
Note: The Microsoft ACE or Microsoft Jet engine handles the SCANTEXT= option.
Note: These TypeGuessRows and ImportMixedTypes registry settings could affect
the behavior of the SCANTEXT= option. Refer to the Table 6.6 on page 43
table for additional information.
Alias: SCAN_TEXT | SCANMEMO
Microsoft Excel Workbook Files 43
TypeGuessRows An integer type with a default value of 8. The number of rows in the
worksheet range is used to scan to determine column types. If set to 0,
all rows in the range are checked. Microsoft states that the valid range
of TypeGuessRows is 0 to 16. However, it could be set as high as 16384
and still operate correctly.
ImportMixedTypes A string type with a default value of Text. If a column contains more
than one data type when scanning of TypeGuessRows rows, the column
type is determined to be Text if the setting value is Text. If the setting
value is Majority Type, the most common column type determines the
column type.
SCANTIME=YES | NO
specifies whether to scan the time data while importing data from a time column
from the Microsoft Excel workbook.
YES scans the time column and assigns the TIME. format for a time column.
NO specifies to not scan the time column. The DATETIME format is assigned if
USEDATE= NO. The TIME. format is assigned if USEDATE= YES.
SERVER= PC-Files- Server-name
specifies the name of the PC Files Server, where PC-Files-Server-name can be either
the computer name or the associated IP address. You must bring up the listener on
the PC Files Server before you can establish a connection. You can configure the
service name, port number, maximum number of concurrent connections allowed,
and data encryption on your PC Files Server.
Alias: SERVER_NAME
Restriction: Available only for client/server model.
Note: You can omit this option if you are running SAS and the PC Files Server on
the same machine. Omitting this option under this condition causes the PC Files
Server to start automatically in the background.
See: “PC Files Server Administration” on page 162.
SERVERPASS= server-user-password
specifies the password for the User ID given. If the account has no password, omit
this option. Always enclose the value in quotes, this preserves the case of the
password.
Alias: SERVERPASSWORD | SERVERPW | SERVERPWD
Notes:
Passwords are generally case sensitive.
Use the PASSWORD= option for database passwords.
Example: LIBNAME using explicit user name and password, for PC Files Server:
LIBNAME DB PCFILES PATH=’C:\myfile.mdb’
SERVER=fileserv;
SERVERUSER=’mydomain\myusername’;
SERVERPASS=’mypassword’;
TIP If you are not on a domain, omit the domain name and the backslash.
SERVERUSER= server-user-name
specifies a domain and User ID that is valid for the PC running PC Files Server.
Always enclose the value in quotes. Otherwise, the backslash can be misinterpreted
by the SAS parser.
44 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Alias: SERVERUID
Notes:
If you are not on a domain, omit the domain name and the backslash.
Use the USER= option for database user IDs.
Example: Here is an example of the LIBNAME statement using explicit user name
and password, used with the PC Files Server.
LIBNAME DB PCFILES PATH=’C:\myfile.mdb’
SERVER=fileserv;
SERVERUSER=’mydomain\myusername’;
SERVERPASS=’mypassword’;
TIP If you are not on a domain, omit the domain name and the backslash.
SERVICE= service-name
specifies the service name that is defined on your service file for your client and
server machines. This port number or service name is displayed on the PC Files
Server control panel screen when it is started on the PC. The service name needs to
be defined on your UNIX machine and your PC Files Server.
Alias: SERVICE_NAME
Restrictions:
Available only for the client/server model.
The SERVICE= statement option and the PORT= statement option should not be
used in the same procedure.
SHEET= sheet-name
identifies a particular worksheet in an Excel workbook. Use the SHEEToption only
when you want to import an entire worksheet. The sheet-name can contain up to 31
characters. If the EXPORT procedure sheet-name contains special characters (such
as space) SAS converts it to an underscore.
The following examples demonstrate how SAS converts non-compliant sheet names.
• The space is converted to an underscore. Employee Information becomes
Employee_Information
• If the sheet name contains single quotes, keep the single quotes as part of the
sheet name in order to be able to access the sheet. SHEET="'My#Test'";
Restriction: Avoid sheet names that look like cell references, which have <1–3
characters> plus 1 or more digits. For example, A1, IV65536, TRY123,
XFD1048576.
Notes:
It is recommended that you use the RANGE= option without the SHEET= option
in the IMPORT procedure.
If both the range name and the sheet name are missing, the IMPORT procedure
reads the first worksheet that was physically saved in the Excel file.
SSPI= YES | NO
enables the server administrator to allow Integrated Windows Authentication. This is
a mechanism for the Windows client and server to exchange credentials.
Default: NO
Restriction: Valid only on a 64-bit Windows PC.
Note: SSPI can also be enabled by specifying the –SSPI option on the SAS
command line.
Microsoft Excel Workbook Files 45
TEXTSIZE= 1 to 32767
specifies the SAS maximum variable length that is allowed while importing data
from Microsoft Excel text columns. Any text data in Excel whose length exceeds this
value is truncated when it is imported into SAS.
Alias: DBMAX_TEXT
USEDATE= YES | NO
specifies whether to assign a DATE format while importing a date column from a
Microsoft Excel workbook.
YES specifies the DATE9. format for the corresponding date column in the Microsoft
Excel table.
NO does not specify the DATE9. format for the corresponding date column in the
Microsoft Excel table.
See:
SCANTIME= statement on page 43 to assign the appropriate TIME format.
“Processing Date and Time Values between SAS and Microsoft Excel” on page
153
VERSION= file-version
specifies the version of the file that you want to create. Valid values are 2007, 2003,
2002, 2000, 97, 95, and 5.
Default: 97 for .xls files
Restrictions:
If the file exists on the PC Files Server, this statement is ignored.
Available only for client/server model.
Note: Always enclose the version in single quotes.
Example 2: Import a Range from Excel 2007 File to a SAS Data Set
This example imports a range named INVOICE from an Excel workbook file and
performs these tasks:
• uses the first row of data as column names
• scans length for character type columns
• assigns DATE9. or TIME8. format to date and time columns respectively
• leaves SAS labels blank
• limits the size of text fields to be less than or equal to 512 characters
PROC IMPORT OUT= WORK.INVOICE
FILE= "&demodir.demo.xlsb"
DBMS= EXCEL REPLACE;
RANGE= 'INVOICE';
GETNAMES= YES;
46 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
SCANTEXT= YES;
USEDATE= NO;
SCANTIME= YES;
DBSASLABEL= NONE;
TEXTSIZE=512; /* default is 1024 */
RUN;
option. The ACCESS procedure and the DBLOAD procedure have other SAS 6
limitations such as a maximum of 8-byte SAS variable names and a maximum of
200-character value.
The following table lists the statements that are available to import data from or export
data to an Excel file using the EXPORT and IMPORT procedures.
Table 6.7 Statements for Importing and Exporting Excel 4 and Excel 5 Files
GETNAMES= YES | NO
specifies whether the IMPORT procedure is to generate SAS variable names from
the first record of the Microsoft Excel import file.
If data in the first record of the input file contains special characters for a SAS
variable name (such as a blank), SAS converts the character to an underscore. For
example, the data value MY ID becomes the SAS variable name MY_ID.
YES specifies that the IMPORT procedure generate SAS variable names from the
data values in the first record of the imported Excel file.
NO specifies that the IMPORT procedure generate SAS variable names as F1, F2,
F3, and so on.
Default: YES
Restrictions:
Valid only for Windows.
Valid only for the IMPORT procedure.
Supported only when DBMS=EXCEL5.
When SAS reads the data value in the first row of the input file, SAS checks for
invalid SAS name characters (such as a blank). Invalid characters are converted
to an underscore. For example, the data value Occupancy Code becomes the SAS
variable name Occupancy_Code.
RANGE= range-name | absolute-range
subsets a specified section of an Excel file worksheet. The range- name is the name
that is assigned to a range address within the worksheet. Range names are not case
sensitive. The range-address is identified by the top left cell that begins the range and
48 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
the bottom right cell that ends the range within the Excel worksheet file. The
beginning and ending cells are separated by two periods. For example, the range
address C9..F12 indicates a cell range that begins at Cell C9, ends at Cell F12, and
includes all cells in between.
SHEET= sheet-name
identifies one worksheet from a group of worksheets while you are reading from an
Excel file. The sheet name can be up to 31 characters. The SHEET statement is
optional.
Import and Export Microsoft Excel Files Using XLS and XLSX File
Formats
This Import/Export component uses the translation engine method to read and write XLS
file formats directly. This component supports Excel versions 5/95, 97, 2000, 2002, and
2003. However, it does not support Excel 2007 .xlsx, .xlsb, or .xlsm files. It is available
on Linux, UNIX, and Microsoft Windows operating platforms.
These tables list the statements that are available to import data from or export data to an
Excel file.
Microsoft Excel Workbook Files 49
Table 6.8 Available Statements for Importing and Exporting Excel Files Using the Translation Engine
PROC PROC
Data Source Syntax Valid Value Default Value IMPORT EXPORT
XLS ENDCOL Last column for Last column that contains Yes No
data data
ENDROW Last row for Last row that contains data Yes No
data
STARTROW First row for First row that contains data Yes No
data
ENDCOL= last-column-for-data
specifies the last column for data
Default: The last row that contains data.
Restriction: Available only for DBMS=XLS for backward compatibility.
ENDNAMEROW= name-row
specifies the last row for variable names.
Default: The same as NAMEROW
Restriction: Available only for DBMS=XLS for backward compatibility.
ENDROW= 1 to 65535
specifies the last row for data.
Default: The last row that contains data.
Restriction: Available only for DBMS=XLS for backward compatibility.
50 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
GETNAMES= YES | NO
determines whether to generate SAS variable names from the data values in the first
record of the imported file. If data in the first record is read and it contains characters
that are not valid in a SAS name, SAS converts the character to an underscore.
For example, the data value Occupancy Code becomes the SAS variable name
Occupancy_Code.
YES specifies that PROC IMPORT is to generate SAS variable names from the data
values in the first record of the imported Excel file.
NO specifies that PROC IMPORT is to generate SAS variable names as VAR1,
VAR2, VAR3, and so on.
Restrictions:
Available only for DBMS=XLS for backward compatibility.
PROC IMPORT only
NAMEROW= name-row
specifies the first row for variable names.
Default: The first row that contains variable names.
Restriction: Available only for DBMS=XLS for backward compatibility.
NEWFILE= YES | NO
when exporting a SAS data set to an existing Excel file, specifies whether to delete
the Excel file, and load the data to a sheet in a new Excel file.
YES specifies that the EXPORT procedure deletes the specified Excel file, if it exists.
Loads the SAS data set to a sheet in a new Excel file.
NO specifies that the EXPORT procedure loads the SAS data set to a sheet and
appends it to the existing Excel file. If the specified Excel file does not exist, an
Excel file is created, and the SAS data set is loaded.
Restriction: Available only for DBMS=XLS for backward compatibility.
PUTNAMES= YES | NO
determines whether to write SAS variable names to the first record of the exported
data file. If you specify the LABEL option, SAS variable labels are written instead of
variable names.
YES specifies that PROC EXPORT is to write SAS variable names to the first record
and write the first observation data to the second record of the exported data file.
NO specifies that PROC EXPORT is to write the first observation data to the
exported data file.
Restrictions:
Available only for DBMS=XLS for backward compatibility.
PROC EXPORT only.
RANGE= ‘range-name’ | ‘absolute-range’;
subsets a spreadsheet by identifying the rectangular set of cells to import from the
specified spreadsheet. The range name is a name that represents a range of cells
within the spreadsheet in the Excel file. Absolute range identifies the top left cell that
begins the range and the bottom right cell that ends the range. For
example, ’C2..F12’ represents cells within column C, row 2, and column F, row 12.
You need to specify the target sheet name with SHEET= if you use absolute range.
By default, the first row is viewed as containing variable names. If GETNAMES=N,
the column is set to the 1- or 2-letter ID, and all rows are read as data.
Microsoft Excel Workbook Files 51
If you do not specify RANGE=, PROC IMPORT reads the entire worksheet as a
range.
Use RANGE= instead of STARTCOL=, STARTROW=, ENDCOL=, ENDROW=,
or any combination of these because RANGE= already contains all of these values.
Restriction: This statement is not valid for PROC EXPORT.
SHEET= ’sheet-name’
identifies a particular worksheet in an Excel workbook. Specify sheet-name to name
the sheet name as output. If the sheet already exists, it is replaced. You can also use
it to append a new sheet to an existing worksheet.
If you do not specify this statement, PROC IMPORT reads the first worksheet
physically saved in the Excel file. To be certain that PROC IMPORT reads the
worksheet that you want, specify SHEET= to identify the worksheet.
Even if you can specify the SHEET= statement in PROC IMPORT for EXCEL4, the
value is ignored. Excel version 5/95 allows multiple sheets in a file, but this export
component supports only exporting a single sheet per file.
For PROC EXPORT, if you specify the SHEET= statement, the name defines the
sheet name and range name in the exported Excel file. The underscore character
replaces the special character for both the range and sheet names. If you do not
specify the SHEET= statement, the SAS data set name defines the sheet name and
range name in the exported Excel file.
STARTCOL= start-column
specifies the first column for data.
Default: The first column that contains data.
STARTROW= start-row
specifies the first row for data.
Default: The first row that contains data.
Restriction: Available only for DBMS=XLS for backward compatibility.
Table 6.9 Microsoft Access Database (.mdb and .accdb) Maximum Size Limits per Method
255 characters
Record size For .mdb: 2000 characters (excluding memo and OLE
object fields)
For .accdb: 4000 characters (excluding memo and OLE
object fields)
While importing data from a table, SAS converts special characters in a table name to
underscores in the corresponding data set name. If a field contains special characters,
SAS converts special to underscores in the corresponding variable name.
The Conversion of Date and Time Values between SAS Data Sets
and Microsoft Access Database
In Microsoft Access database software, the following date and time rules apply:
• Date values are valid back to 30 December 1899 and are saved as the integer value:
0.
• Date values are valid ahead to 31 December 9999, and are saved as the integer value:
2,958,465.
• Years 4000 and 8000 are considered leap years.
• Time value is the decimal portion of a number that represents time as a proportion of
a day.
• Numbers can have both a date and a time portion, the format is in date/time format.
• Number display formats support date, time, or date/time formats.
In SAS software, the following date and time rules apply:
• Dates are valid back to A.D.1582.
• Date values before year 1582 are represented as missing values.
• Dates are valid forward to A.D. 9,999.
• Date values are represented by the number of days between January 01, 1960, and
that date.
• Years 4000 and 8000 are not considered leap years.
• Time values are represented by the number of seconds between midnight and that
time of day.
• Date and time values are represented by the number of seconds between midnight
January 01, 1960, and that date and time.
• Time values can be imported as a date value 30 Dec 1899. Ensure that you assign the
correct format.
Overview
Before you use the IMPORT and the EXPORT procedures for Access files, it is helpful
to be familiar with Access file formats. For an existing .mdb file, you can specify
DBMS=ACCESS on Windows platforms, and SAS identifies the version.
• Access 2000, 2002, and 2003 share the same .mdb file formats. ACCESS2000,
ACCESS2002, and ACCESS2003 are treated as aliases for Access in SAS.
• Access 2007 supports .accdb file formats.
See “Example 1: Import a SAS Data Set from an Access 2007 Database Table” on page
61 and “Example 2: Export a SAS Data Set to Create an Access Database File” on page
61 for additional information.
Microsoft Access Database Files 55
Table 6.10 IMPORT and EXPORT Procedure Statements for Access Files on Windows
PROC PROC
Data Source Syntax Valid Value Default Value IMPORT EXPORT
On Linux, UNIX, and Microsoft Windows operating platforms, you can use the client/
server model to access data in .mdb files and .accdb files. For more information, see “PC
Files Server Administration” on page 162.
For an existing .mdb you can specify DBMS=ACCESSCS when using the client/server
model and SAS identifies the version of Access for you. You can specify VERSION =
'97' when using the client/server model only when you want to export and create a
new .mdb file with Access version 97 formats.
Note: If the client/server model is used, the SAS client cannot access an Access
database file with both database password protection and user level security
protection. In this case, you must choose only one security protection to be able to
access your Access database file from a SAS client.
The following table lists the statements to import or export data to or from an Access
database file using the client/server model. The statements are valid on Linux, UNIX,
and Microsoft Windows operating platforms.
56 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Table 6.11 IMPORT and EXPORT Procedure Statements for Access Files When Using PC Files Server
PROC PROC
Data Source Syntax Valid Value Default Value IMPORT EXPORT
DATABASE= database
specifies the complete path and filename of the Access database file that contains the
specified DBMS table. If the database name does not contain lowercase characters,
special characters, or national characters ($, #, or @), you can omit the quotation
marks.
Note: SAS does not generate a default value, but you can configure one in the
DBMS client software.
DBDSOPTS= data set options that are valid for the Access database LIBNAME
engine
Enables you to take advantage of useful data set options for the LIBNAME engine
such as READBUFF= , INSERTBUFF= , DBTYPE=, DROP= , FIRSTOBS= , and
OBS=. This option is for advanced users who are familiar with the PC files
LIBNAME engine.
Requirements:
You must surround the options in single quotation marks.
/* Example of correct use */
DBDSOPTS=’FIRSTOBS=10 READBUFF=25’;
If the option string that you are specifying contains single quotation marks, you
must use double quotation marks around it in your statement.
/*Example of correct use */
DBDSOPTS="DBTYPE=(BilledTo=’CHAR(8)’)";
Notes:
For users who use the client/server model to access data in an Access database,
the default value for READBUFF= is 1. To improve performance for reading
data, you should set the READBUFF= option to 25 or higher.
For users who use the client/server model to access data in an Access database,
the default value for INSERTBUFF= is 1. To improve performance for reading
data, you should set the INSERTBUFF= option to 25 or higher.
See: “Data Set Options for PCFILES on Linux, UNIX, and Microsoft Windows”
on page 186
DBPASSWORD= database-file-password
enables you to access a file if database-level security is set in the .mdb file. This
option enables you to access .mdb and .accdb files with passwords, but it does not
allow you to create .mdb and .accdb files with passwords included. A database
password is case sensitive. You can define a database password instead of user-level
security.
Alias: DBPWD | DBPW
Due to a limitation in the Microsoft Ace engine and the Microsoft Jet Excel
engine, using MIXED=YES could result in improper text variable lengths.
DBSYSFILE= complete path and filename for the Workgroup Administration file
specifies the location of the Workgroup Administration file. You might have defined
this file, which contains information about the users in a Workgroup, for your
Microsoft Access database.
Alias: WGDB
Note: When you install Microsoft Access, the Setup program automatically creates
a Microsoft Access Workgroup information file that is identified by the name
and organization information that you specify. Because this information is often
easy to determine, it is possible for unauthorized users to create another version
of this Workgroup Information file and assume the irrevocable permissions of an
administrator account (a member of the Admins group) in the Workgroup
defined by that Workgroup Information file. To prevent this, create a new
Workgroup Information file and specify a Workgroup ID (WID). Only someone
who knows the WID can create a copy of the Workgroup Information file. Any
user and group accounts or passwords that you create are saved in the new
Workgroup Information file.
MEMOSIZE= 1 to 32767
Specifies the maximum variable length in SAS that is allowed while importing data
from memo columns of an Access database table. Any memo data in an Access
database tables whose length exceeds 32767 is truncated when it is imported into
SAS.
Alias: DBMAX_TEXT
Restriction: If the maximum length that SCANMEMO = option is greater than the
value of the MEMOSIZE= option, the smaller value in the MEMOSIZE = option
is applied as the SAS variable width.
PORT= port-number
specifies the number of the port that is listening on the PC Files Server. The valid
value is between 1 and 65535. This port or service name displays on the PC Files
Server display when the application is started in server mode.
Alias: PORT_NUMBER
Default: 9621
Restrictions:
Available only for the client/server model.
The PORT= statement option and the SERVICE= statement option should not be
used in the same procedure.
SCANMEMO= YES | NO
specifies whether to scan the memo data to determine the column length for each
memo-type source column.
YES scans the length of memo data for a data source column. Uses the length of the
longest memo text of data that it finds, as the SAS variable width.
NO does not scan the length of memo data for a data source column. The column
length returned from the Microsoft Ace engine or the Microsoft Jet engine is used as
the SAS variable length.
Restrictions:
When SCANMEMO=YES, if the maximum length that SCANMEMO = option
is greater than the value of the MEMOSIZE= option, the smaller value in the
MEMOSIZE = option is applied as the SAS variable width.
Microsoft Access Database Files 59
SCANMEMO = does not apply to text type columns. This option applies only to
memo data type columns.
SCANTIME= YES | NO
specifies whether to scan the date/time data while importing data from a date/time
column from an Access database.
YES scans the date/time column and assigns the TIME. format for a date/time
column only if time values are found in the column.
NO specifies not to scan the date/time column.
Interactions:
The DATE9. format is assigned for a date/time column if USEDATE= YES.
The DATETIME. format is assigned for a date/time column if USEDATE= NO.
SERVER= PC-Files-Server-name
specifies the name of the PC Files Server, where PC-Files-Server-name can be either
the computer name or the associated IP address. You must bring up the listener on
the PC Files Server before you can establish a connection to it. You can also
configure these items:
• the service name
• the port number
• the maximum number of concurrent connections
• specifications to indicate whether data encryption will be used
Alias: SERVER_NAME
Restriction: Available only for the client/server model.
Note: You can omit this option if you are running SAS and the PC Files Server on
the same machine. Omitting this option under this condition causes the PC Files
Server to start automatically in the background.
SERVERPASS= server-user-password
specifies the password for the User ID given. If the account has no password, omit
this option. Always enclose the value in quotes. This preserves the case of the
password.
Alias: SERVERPASSWORD | SERVERPW | SERVERPWD
Notes:
Passwords are generally case sensitive.
Use the PASSWORD= option for database passwords.
Example: LIBNAME example using explicit user name and password for PC Files
Server:
LIBNAME DB PCFILES PATH='C:\myfile.mdb'
SERVER=fileserv;
SERVERUSER='mydomain\myusername';
SERVERPASS='mypassword';
RUN;
SERVERUSER= server-user-name
specifies a domain and user ID that is valid for the PC running PC Files Server.
Always enclose the value in quotes. Otherwise, the backslash can be misinterpreted
by the SAS parser.
Alias: SERVERUID
Notes:
If you are not on a domain, omit the domain name and the backslash.
Use the USER= option for database User IDs.
60 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Example: LIBNAME using explicit user name and password, for PC Files Server:
LIBNAME DB PCFILES PATH='C:\myfile.mdb'
SERVER=fileserv;
SERVERUSER='mydomain\myusername';
SERVERPASS='mypassword';
RUN;
SERVICE= service-name
specifies the service name that is defined on your service file for your client and
server machines. This port number or service name is displayed on the PC Files
Server control panel screen when it is started on the PC in server mode.
Alias: SERVICE_NAME
Restrictions:
Available only for client/server model.
Do not use this statement and the PORT= statement option in the same
procedure.
Note: This service name needs to be defined on both your UNIX machine and your
PC Files Server.
SSPI= YES | NO
enables PC Files Server to allow Integrated Windows Authentication. This is a
mechanism for Windows client and server to exchange credentials.
Default: NO
Restriction: Valid only on Windows 64-Bit.
Note: SSPI can also be enabled by specifying the –SSPI option on the SAS
command line.
Example: LIBNAME using SSPI:
LIBNAME DB PCFILES PATH='C:\myfile.mdb'
SERVER=localhost;
SSPI = 'yes';
RUN;
USEDATE= YES | NO
specifies whether to assign a DATE. or a DATETIME. format while importing a
date/time column from a Microsoft ACCESS workbook.
YES assigns the DATE. format for the corresponding date/time column in the
Microsoft ACCESS table. See the SCANTIME = option to assign the appropriate
TIME format.
NO assigns the DATETIME. format for the corresponding date/time column in the
Microsoft ACCESS table.assigns the DATETIME. format for the corresponding
date/time column in the Microsoft ACCESS table.
See:
For processing of date and time values between SAS and Microsoft Access, see
“Processing Date and Time Values between SAS and Microsoft Access” on page
157.
The SCANTIME= statement option on page 43 in order to assign the appropriate
TIME format.
VERSION= file-version
specifies the version of the file that you want to create. Valid values are 2007, 2003,
2002, 2000, and 97. The default value depends on the extension of the file. Always
surround the version value with single quotation marks.
Restriction: Available only for client/server model.
Interaction: If the file exists on the PC Files Server, then the statement is ignored.
Microsoft Access Database Files 61
VERSION='97';
DBDSOPTS='INSERTBUFF=25';
RUN;
Column letters for each column appear above the spreadsheet. Columns are lettered A–
IV (A to Z, AA to AZ, BA to BZ, and so on, to IV). Row numbers for each row appear
to the left of the spreadsheet. Rows are numbered 1 to 8,192. For WK1 files, only one
spreadsheet (spreadsheet A) is allowed per file. For WK3 and WK4 files, up to 256
spreadsheets (spreadsheets A-IV) are allowed. However, the SAS/ACCESS interface to
WKn files uses only one spreadsheet and defaults to spreadsheet A.
A range is a subset of cells in a spreadsheet. A range is identified by its address. The
address begins with the name of the top left cell. The range ends with the name of the
bottom right cell. The names are separated by two periods. For example, the range
B2..E8 is the range address for a rectangular block of 28 cells whose top left cell is B2
and whose bottom right cell is E8 (as shaded in the figure).
You can give a name to a range and use the name in commands and formulas instead of
the range address in Lotus 1-2-3. A range name can be up to 15 characters long and
should contain no spaces. For example, if the range B3..D6 is named GRADE_TABLE,
the formula @AVG(GRADE_TABLE) has the same value as @AVG(B3..D6).
For more information about ranges and their naming conventions, see the Lotus 1-2-3
software documentation.
GETNAMES= YES | NO
specifies whether the IMPORT procedure is to generate SAS variable names from
the data values in the first row of the import file.
If data in the first record of the input file contains special characters for a SAS
variable name (such as a blank), SAS converts the character to an underscore. For
example, the data value MY ID becomes the SAS variable name MY_ID.
YES specifies that the IMPORT procedure generate SAS variable names from the
data values in the first record of the imported Excel file.
NO specifies that the IMPORT procedure generate SAS variable names as F1, F2,
F3, and so on.
Default: YES
Restrictions:
Valid only for DBMS=EXCEL.
Valid only for the IMPORT procedure.
When SAS reads the data value in the first row of the input file, SAS checks for
invalid SAS name characters (such as a blank). Invalid characters are converted
to an underscore. For example, the data value Occupancy Code becomes the SAS
variable name Occupancy_Code.
RANGE= “ range-name” | “ absolute-range”
subsets a spreadsheet by identifying the rectangular set of cells to import from the
specified spreadsheet. Range names can be up to 15 characters long and are not case
sensitive. If you specify a range name, the name must have been previously defined
in the WKn file. Absolute range identifies the top left cell that begins the range and
the bottom right cell that ends the range. For example, `C2..F12' represents cells
within column C, row 2 and column F, row 12. If this statement is not specified,
PROC IMPORT reads the entire spreadsheet as a range.
Restriction: This statement is valid for PROC IMPORT only.
Lotus 1-2-3 WKn Files 65
Example 2: Import Data from a SAS Data Set from a WK4 File
This example imports data from a WK4 file named invoice.wk4 into SAS data set named
Invoice. It retrieves data from Sheet A, within range from left top cell, A1, to right
bottom cell, D12. It then reads the first row of data in the range as SAS variable names.
PROC IMPORT OUT=WORK.Invoice
DATAFILE="&wkndir.Invoice.wk4"
DBMS=WK4 REPLACE;
SHEET='A';
RANGE='A1..D12';
GETNAMES=YES;
RUN;
Example 4: Import Data from a WK1 File into a SAS Data Set
This example imports data from a WK1 file named Orders.wk1 into a SAS data set
named Test. It retrieves data from left top cell, B5, to right bottom cell, D12. SAS
assigns name for each variable as VAR0, VAR1, and VAR2.
PROC IMPORT OUT=WORK.Test
DATAFILE="&wkndir.orders.wk1"
DBMS=WK1 REPLACE;
RANGE='B5..D12';
GETNAMES=NO;
RUN;
ALIAS: CHAR
NUMERIC ( N, n)
specifies a decimal number. The N value is the total number of digits that are used to
express the value (precision). The n value is the number of digits following the
decimal point (scale). The maximum values allowed depend on which software
product you are using.
dBASE II 16, 14
dBASE IV 20, 18
Numeric field types always preserve the precision of their original numbers.
However, SAS stores all numbers internally as double-precision, floating-point
numbers so their precision is limited to 16 digits.
Note: If every available digit in a DBF file field is filled with a 9 , SAS interprets
the value of the field as missing. If a field in SAS indicates a missing value
(represented by a period), SAS writes a nine for each available digit in the
corresponding DBF file database field. While in a SAS session a value is
represented as missing.:
FLOAT N, n)
specifies a floating-point binary number that is available in dBASE IV and later
versions. The maximum N, n value for Float is 20,18. Check with the documentation
that comes with other software products that you might be using to create DBF files
to determine whether those products support floating-point binary numbers.
DATE
specifies a date value in a format that has numbers and a character value to separate
the month, day, and year. The default format is mm/dd/yy. For example, 02/20/95
for February 20, 1995.
Dates in DBF files can be subtracted from one another, with the result being the
number of days between the two dates. A number (of days) can also be added to a
date, with the result being a date.
LOGICAL
specifies a type that answers a Yes | No or True | False question for each row in a
file. This type is 1 byte long and accepts these character values: Y, y, N, n, T, t, F,
and f.
Note: dBASE also has data types called Memo, General, binary, and OLE. These data
types are stored in an associated memo text file (a DBT file). These data types are
not supported in theSAS/ACCESS Interface to PC Files.
68 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
Table 6.14 IMPORT and EXPORT Procedure Statements for DBF Files
Example 2: Import Data from a DBF File into a SAS Data Set
This example imports data from a DBF file named invoice.dbf into SAS data set named
TEST5. The data is imported without the DELETE flag field.
PROC IMPORT OUT=WORK.TEST5
DATAFILE="&dbfdir.Invoice.dbf"
DBMS=DBF REPLACE;
70 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
GETDEL=NO;
RUN;
Example 3: Export Data to a DBF File from a SAS Data Set Using
Encoding
This example exports data from a SAS data set named SDF.ORDERS to a DBF file
named Oem850.dbf. The procedure translates SAS data from its current session
encoding, to pcoem850 encoding and writes it to the DBF file.
PROC EXPORT DATA=SDF.ORDERS
OUTFILE="&dbfdir.Oem850.dbf"
DBMS=DBF REPLACE;
DBENCODING=pcoem850;
RUN;
Overview
When you use the DBFMEMO engine to import dBase Memo fields into the SAS
System, the fields can be imported into multiple variables with numeric suffixes
appended. When a Memo field is imported, each line of the field is imported as a separate
variable. Each variable is given a numeric suffix to distinguish the particular line of the
Memo field that was read. For example, a dBase Memo field of AE1 is imported as
AE11, AE12, and so on.
All versions of dBase under Linux, UNIX, and Microsoft Windows are supported.
Memo files have a .dbt (dBase) or .fpt (FoxPro and Visual FoxPro) file extension.
Note: Memo support is read only.
If a memo file exists with the same filename but with a .dbt or .fpt extension, the driver
also reads the memo text for that file. It scans the memo file to determine how many
lines comprise the largest individual memo and the lengths of the longest lines. It then
splits memos into one variable per memo line. For example, the first three lines of a
memo file called xyz would be named xyz01, xyz02, and xyz03.
JMP Files 71
Import Data from a DBF File with Memo Field into a SAS Data Set
This example imports data from a DBF file named orders.dbf into a SAS data set named
TEST.
PROC IMPORT OUT=WORK.TEST
DATAFILE='orders.dbf'
DBMS=DBFMEMO REPLACE;
RUN;
JMP Files
in an existing name, the last character changes to a single digit (1,2, 3...) until the
variable name becomes unique.
VALUE LABELS
SPSS stores value labels within the data file. The values are turned into format
library entries as they are read with the IMPORT procedure. The name of the format
includes its associated variable name, modified to meet the requirements of format
names. The name of the format is also associated with a variable in the data set. You
can use the FMTLIB = libref.format-catalog statement to save the formats catalog in
a specified SAS library.
The EXPORT procedure saves the value labels that are associated with the variables
when writing to an SPSS file. The procedure uses the formats that are associated
with the variables to retrieve the value entries. You can use the FMTLIB =
libref.format-catalog statement to tell SAS the location of the format catalog.
VARIABLE LABELS
SPSS supports variable labels. the EXPORT procedure writes the variable name to
an SPSS file as the label if the variable name is not a valid SPSS name and no label
exists.
DATA TYPES
SPSS supports numeric and character field types that map directly to SAS numeric
and character fields. This list shows other SPSS data types and how the IMPORT
procedure converts them to SAS formats.
Date, Jdate, Wkday, Qyr, Wkyr: Date, Jdate, Wkday, Qyr, Wkyr
Datetime, Dtime: Converts to a SAS datetime value and SAS datetime format.
Time: Converts to a SAS datetime value and SAS datetime format.
Adate: Converts to a SAS date value in the mmddyy format.
Moyr: Converts to a SAS date value in the mmmyy format.
When writing SAS data to an SPSS file, the EXPORT procedure converts data into
SPSS variable types.
When exporting data, character fields have a maximum length of 256.
Numeric fields are 8 byte floating-point numbers, with these format conversions:
COMMA
Converts to SPSS format type comma.
DOLLAR
Converts to SPSS format type dollar.
DATE
Converts to SPSS format type date.
MMDDYY
Converts to SPSS format Adate.
MMMYY
Converts to SPSS format Moyr.
DATETIME
Converts to SPSS format Dtime.
TIME
Converts to SPSS format Time.
SPSS SAV Files 77
numerals. No other characters are permitted. Stata reserves the 19 words shown in
the table below, which are not allowed to stand alone as variable names:
_all _n
in using
_pred double
_b _N
int _weight
_rc float
_coef pi
long with
_skip if
_cons
If the program encounters any of these reserved words as variable names, it appends
an underscore to the variable name to distinguish it from the reserved word. For
example, _N becomes _N_.
When exporting, variable names greater than 32 characters are truncated. The first
character in a variable name can be any lowercase letter or uppercase letter or an
underscore. Subsequent characters can be any of these characters plus numerals. No
other characters are permitted. Invalid characters are converted to underscores.
VARIABLE LABELS
Stata supports variable labels when using the IMPORT procedure. When exporting,
if the variable name is not a valid Stata name and there is no label, the EXPORT
procedure writes the variable name as the label.
VALUE LABELS
Stata stores value labels within the data file. The value labels are converted to format
library entries as they are read with the IMPORT procedure. The name of the format
includes its associated variable name modified to meet the requirements of format
names. The name of the format is also associated with a variable in the SAS data set.
You can use FMTLIB= libref.format-catalog statement to save the formats catalog
under a specified SAS library.
When writing SAS data to a Stata file, the EXPORT procedure saves the value labels
that are associated with the variables. The procedure uses the formats that are
associated with the variables to retrieve the value entries. You can use the FMTLIB=
libref.format-catalog statement to tell SAS where to locate the formats catalog.
Note: Numeric formats only.
DATA TYPES
Stata supports numeric field types that map directly to SAS numeric fields.
Stata date variables become numerics with a date format.
80 Chapter 6 • File Format-Specific Reference for the IMPORT and EXPORT Procedures
When writing SAS data to a Stata file, the EXPORT procedure converts data into
variable type double. A SAS date format becomes a Stata date variable.
DBMS=PCFS REPLACE;
SERVER="&server";
RUN;
Part 3
Chapter 7
Interaction and Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Chapter 8
The LIBNAME Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Chapter 9
The LIBNAME Statement for Access and Excel on Microsoft
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Chapter 10
Data Set Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Chapter 11
LIBNAME Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Chapter 12
Pass-Through Facility for Access and Excel on Microsoft Windows .
129
Chapter 13
File-Specific Reference for Access and Excel on Microsoft Windows
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
84
85
Chapter 7
Interaction and Functionality
values. If the sort encounters NULL values, are they listed at the beginning or end of the
result set. NULL values are translated in SAS to missing values.
• Name: up to eight alphanumeric characters. The library reference (libref) that you
want to assign. Use the libref to point SAS to a SAS library or an external data
source.
• Engine: select the engine that you want to use. The default engine enables SAS to
choose which engine to use based on the existing data sets in a library. If no data sets
exists in the same location as your new library, the Base SAS engine is assigned.
Assigning a Libref Interactively 87
• Enable at startup: select to assign the specified libref to automatically when you
open a SAS session. If you select Enable at Startup, you must go to Solutions ð
Accessories ð Registry Editor ð CORE ð OPTIONS ð LIBNAMES to remove
the libref.
• Path: specifies the path of the libref.
• Library Information: represents the SAS/ACCESS connection options and vary
according to the SAS/ACCESS engine that you specify. Enter the appropriate
information for your PC file format.
• OK: click this button to assign the libref, or click Cancel to exit the window without
assigning a libref.
88 Chapter 7 • Interaction and Functionality
89
Chapter 8
The LIBNAME Engines
Software Requirements
On Windows, SAS/ACCESS Interface to PC Files supports a LIBNAME engine for
Microsoft Access database files and a LIBNAME engine for Excel workbook files.
These two engines share most of code that calls OLE DB APIs internally. They require
that you have installed Microsoft Data Access Components (MDAC) and Microsoft Jet
(Joint Engine Technology) or Microsoft Ace (for 2007 and above) provider software. By
default, SAS software installs and checks the required Microsoft software.
Macro Variables
The automatic macro variables SYSDBMSG, SYSDBRC, SQLXMSG, and SQLXRC
are portable, but the SAS/ACCESS engine and the Microsoft Jet Engine determine their
values. Initially, the macro variables SYSDBMSG and SQLXMSG are blank, whereas
SYSDBRC and SQLXRC are set to 0.
SAS/ACCESS generates several return codes and error messages while it processes your
programs. This information is available to you through these SAS macro variables:
SASTRACE 91
SYSDBMSG
contains Jet provider-specific error messages that are generated when you use
SAS/ACCESS software to access Microsoft Access or Excel data.
SYSDBRC
contains Jet provider-specific error codes that are generated when you use
SAS/ACCESS software to Microsoft Access or Excel data. Error codes that are
returned are text, not numbers.
In this statement, %SUPERQ masks special characters such as &, %, and any
unbalanced parentheses or quotation marks that might exist in the text stored in the
SYSDBMSG macro.
%put %superq(SYSDBMSG)
These special characters can cause unpredictable results if you use this statement, so it is
more advantageous to use %SUPERQ.
You can also use SYMGET to retrieve error messages:
MSG=SYMGET("SYSDBMSG");
SYMGET example:
DATA_NULL_;
MSG=SYMGET("SYSDBMSG");
PUT MSG;
RUN;
The pass-through facility generates return codes and error messages that are available to
you through these SAS macro variables:
SQLXMSG
contains Jet provider-specific error messages.
SQLXRC
contains Jet provider-specific error codes.
SQLXMSG and SQLXRC can be used only with the pass-through facility. See “Return
Codes” on page 130 for additional information.
The contents of the SQLXMSG and SQLXRC macro variables can be printed in the
SAS log by using the %PUT macro. SQLXMSG is reset to a blank string and SQLXRC
is reset to 0 when any pass-through facility statement is executed.
System Options
SASTRACE = and SASTRACELOC = are SAS system options that have specific
SAS/ACCESS applications.
Dictionary
SASTRACE
Generates trace information from a DBMS engine.
92 Chapter 8 • The LIBNAME Engines
Syntax
SASTRACE=',,,d' | ' ,,d,' | ' d,' | ',,,s'
Syntax Description
',,,d'
specifies that all of these SQL statements sent to the Microsoft Jet engine are sent to
the SAS log:
SELECT INSERT
UPDATE DROP
CREATE DELETE
',,d,'
specifies that all routine calls are sent to the log. When this option is selected, all
function enters and exits, as well as pertinent parameters and return codes, are traced.
However, the information varies from engine to engine.
This option is most useful if you are having a problem and need to send a SAS log to
technical support for troubleshooting.
'd,'
specifies that all OLE DB API calls for connection information, column bindings,
column error information, and row processing are sent to the log. This option is most
useful if you are having a problem and need to send a SAS log to technical support
for troubleshooting.
',,,s'
specifies that a summary of timing information for calls made to the DBMS is sent to
the SAS log.
Details
The SASTRACE= option has behavior that is specific to SAS/ACCESS software.
SASTRACE= is a very powerful tool to use when you want to see the commands that
the SAS/ACCESS engine sends. SASTRACE= output is DBMS-specific. However,
most SAS/ACCESS engines show statements like SELECT or COMMIT as the DBMS
processes them for the SAS application. These details can help you manage
SASTRACE= output for your files:
• When using SASTRACE= on PC platforms, you must also specify
SASTRACELOC= options, as described in “SASTRACELOC” on page 94.
• To turn SAS tracing off, specify this option:
options sastrace=off;
• Log output is much easier to read if you specify NOSTSUFFIX. Here is an example:
OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;
Note: By default, Microsoft Access and Microsoft Excel LIBNAME engines use
ROWSET_INSERT instead of executing the SQL INSERT command. You do not
see the INSERT statement in the trace log when inserting rows into a table. You can
use the LIBNAME statement or the SQL_INSERT=YES option to see the INSERT
statement in the trace log.
SASTRACE 93
1 DATA WORK.winter_birthdays;
2 INPUT empid birthdat date9. lastname $18.;
3 FORMAT birthdat DATE9.;
4 DATALINES;
NOTE: The data set WORK.WINTER_BIRTHDAYS has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
CPU time 0.04 seconds
8 ;
9 RUN;
10
11 OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;
12 LIBNAME mydblib 'c:\sasdemo\demo.mdb' ;
NOTE: Libref MYDBLIB was successfully assigned as follows:
Engine: ACCESS
Physical Name: c:\sasdemo\demo.mdb
13
14 proc delete data=mydblib.snow_birthdays; RUN;
Jet_0: Executed:
DROP TABLE `snow_birthdays`
NOTE: Deleting MYDBLIB.snow_birthdays (memtype=DATA).
NOTE: PROCEDURE DELETE used (Total process time):
real time 0.01 seconds
CPU time 0.00 seconds
15
16 DATA mydblib.snow_birthdays;
17 SET work.winter_birthdays;
18 RUN;
NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.
Jet_1: Executed:
CREATE TABLE `snow_birthdays` (`empid` Double,`birthdat` DateTime,`lastname`
VarChar(18))
NOTE: There were 3 observations read from the data set WORK.WINTER_BIRTHDAYS.
NOTE: The data set MYDBLIB.snow_birthdays has 3 observations and 3 variables.
NOTE: Successfully Inserted 3 row(s)
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
CPU time 0.01 seconds
19
20 LIBNAME mydblib clear;
NOTE: Libref MYDBLIB has been deassigned.
SASTRACELOC
Writes SASTRACE information to a specified location.
Valid in: OPTIONS statement, configuration file, SAS invocation
Default: stdout
Syntax
SASTRACELOC= stdout | SASLOG | FILE 'path-and-filename'
Details
specify where to put the trace messages that are generated by SASTRACE=. By default,
the output goes to the default output location for your operating environment. You can
send the output to the SAS log by specifying SASTRACELOC=SASLOG.
SASTRACELOC 95
Chapter 9
The LIBNAME Statement for
Access and Excel on Microsoft
Windows
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
LIBNAME Statement Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Dictionary
Syntax
LIBNAME < libref> engine-name <physical-path and filename>
<SAS/ACCESS engine-connection-options>
<SAS/ACCESS LIBNAME-options> ;
LIBNAME libref CLEAR| _ALL_;
LIBNAME libref LIST| _ALL_;
Optional Arguments
libref
is any SAS name that associates SAS with the SAS library where the spreadsheet or
database is stored.
engine-name
is the SAS/ACCESS engine name for your PC file format. The SAS/ACCESS
LIBNAME statement associates a libref with a SAS/ACCESS engine that supports
connections to a particular PC file type. The supported engine-names are as follows:
EXCEL for Microsoft Excel 5, 95, 97, 2000, 2002, 2003, 2007, and 2010.
ACCESS for Microsoft Access 97, 2000, 2002, 2003, 2007, and 2010.
Note: The engine name is optional if the physical-path-filename.ext is specified. The
file extension provides enough information for SAS.
Examples:
98 Chapter 9 • The LIBNAME Statement for Access and Excel on Microsoft Windows
This example illustrates two options for using LIBNAME statement with
physical filename, including the file's extension. The accdb file extension
provides SAS information about the data type. The PATH= option provides SAS
with the location of the data.
LIBNAME libref ACCESS PATH='C:\PCFData\Demo.accdb';
or
LIBNAME libref 'C:\PCFData\Demo.accdb';
This LIBNAME statement specifies xdb as a reference to a SAS library. The
EXCEL engine specifies the engine that supports the connection to the file
type .XLSX.
LIBNAME xdb EXCEL PATH='C:\PCFData\Demo.xlsx';
physical-path- filename.ext
is the physical-path and filename.ext of the data source.
• Microsoft Excel data source extensions include: .XLS, .XLSB, .XLSM, .XLSX.
• Microsoft Access extensions include: .MDB and .ACCDB.
Note: Providing the physical-path–filename.ext sets the NOPROMPT ENGINE
option.
See: "Connection Details" on page 101 Details on page 101
Example: Physical Path and Filename Omitting Engine Name:
LIBNAME xdb 'C:\PCFData\Demo.xlsx';
LIBNAME adb 'C:\PCFData\Demo.accdb';
CLEAR
clears one libref.
Specify libref to disassociate a single libref.
_ALL_
specifies that the CLEAR or LIST argument applies to all librefs.
LIST
writes the attributes of one or more SAS/ACCESS libraries or SAS libraries to the
SAS log.
Specify libref to list the attributes of a single SAS/ACCESS library or SAS library.
Specify _ALL_ to list the attributes of all librefs in your current session.
Examples:
List the attributes of a single library:
LIBNAME LIBREF LIST;
List the attributes of all the libraries.
LIBNAME _ALL_ LIST;
SAS/ACCESS engine-connection-options
provide connection options to SAS/ACCESS to connect to your PC files. If the
connection options contain characters that are not allowed in SAS names, enclose the
values in quotation marks. In some instances, if you specify the appropriate system
options or environment variables for your data source, you can omit the connection
options.
See: “Connection Details” on page 101
SAS/ACCESS LIBNAME-options
define how SAS interacts with your data source, providing enhanced control of the
way that SAS processes data source objects. For example, some LIBNAME options
can improve performance. For many tasks that you do not need to specify any of
these advanced options.
LIBNAME Statement Syntax 99
Connection Options
SAS/ACCESS provides many ways to connect to your PC files.
INIT= connection-string
used for OLEDB, specifies an initialization string that SAS uses when connecting to
a data source.
Alias: INIT_STRING
Restriction: This option should not be used with a physical filename or other
connection options, such as PATH and UDL.
Note: This is used rarely, specifically in SAS 9.2 and later, with the Microsoft ACE
engine being dominant.
MSENGINE= ACE | JET
determines the database engine used for accessing the Microsoft Excel file or
Microsoft Access database. The Microsoft Jet engine is older and supports formats
up to 2003. The Microsoft Ace engine supports 2007 and older formats.
Default: ACE
NO prompting is not available. You must specify the data source as a physical
filename or complete path.
REQUIRED enables connection without prompting for more information. If a valid
connection is not specified, you are prompted for the connection options. The prompt
enables you to change the data source file and other properties.
Note: You must specify a valid physical filename for a successful connection.
NOPROMPT prompting is not available.
PROMPT enables prompting for connection information for the data source.
UDL enables browsing so you can select an existing data link file (.udl).
UDL= path-for-udl-file
specifies the path and filename for a UDL file (a Microsoft data link file) as in this
example.
UDL='C:\WinNT\profiles\me\desktop\MyDBLink.UDL';
%PUT %SUPERQ(SYSDBMSG);
100 Chapter 9 • The LIBNAME Statement for Access and Excel on Microsoft Windows
Alias: UDL_FILE
Restrictions:
This option should not be used with a physical filename or other connection
options, such as PATH and INIT.
This option does not support SAS filerefs. The SYSDBMSG macro variable is
set on successful completion. For more information, refer to Microsoft
documentation about using data link.
DBSYSFILE= workgroup-information-file
specifies the workgroup information file. This file contains a collection of
information defined for the Microsoft Access database. User, group accounts, and
passwords that you create, are saved in the workgroup information file.
Alias: SYSTEMDB
Restriction: Microsoft Access database files only.
PASSWORD= user-password
specifies a password required by the data source for the user account.
Alias: PWD | PW | PASS | PASSWORD
Note: Passwords are case sensitive.
USER= user-id
specifies a user account name, if one is required to connect to the data source. For
Microsoft Access, if you have user-level security set on your .mdb file, you need to
use the USER= and PASSWORD= options to access your file.
Alias: UID
Restriction: Microsoft Access database files only.
Note: Use the SERVERUSER= option to connect to a server.
Details
Using Data from a PC File. You can use a LIBNAME statement to read from and write
to a data source table or view as if it were a SAS data set. The LIBNAME statement
associates a libref with a SAS/ACCESS engine to access tables or views in a spreadsheet
or database. The SAS/ACCESS engine enables you to connect to a particular data source
and to specify an external data object name in a two-level SAS name.
For example,
MyPCLib.Employees_Q2
• MyPCLib is a SAS libref that points to a particular group of external data objects.
• Employees_Q2 is a table name.
When you specify MyPCLib.Employees_Q2 in a DATA step or procedure, you
dynamically access the external data object. SAS supports reading, updating, creating,
and deleting external data objects dynamically.
Clearing Libref from a SAS Library. To disassociate or clear a libref, use a LIBNAME
statement. Specify the libref and the CLEAR option. SAS/ACCESS disconnects from
the data source and closes any free threads or resources that are associated with that
libref's connection.
To clear a single libref:
LIBNAME mypclib CLEAR;
Writing SAS Library Attributes to the SAS Log. Use a LIBNAME statement and the
LIST option to write the attributes of one or more SAS/ACCESS libraries or SAS
libraries to the SAS log.
To list attributes of a single library:
LIBNAME mypclib LIST;
The Demo.mdb database contains a number of objects, including several tables, such as
Staff. After you assign the libref, you can reference the Microsoft Access table like a
SAS data set. You can also use it as a data source in any DATA step or SAS procedure.
In this PROC SQL statement, MyMdb.Staff is the two-level SAS name for the Staff
table in the Microsoft Access database Demo.
PROC SQL;
SELECT idnum, lname
FROM mymdb.staff
WHERE state='NY'
ORDER BY lname;
QUIT;
You can use the Microsoft Access data to create a SAS data set:
102 Chapter 9 • The LIBNAME Statement for Access and Excel on Microsoft Windows
DATA newds;
SET mymdb.staff(KEEP=idnum lname fname);
RUN;
You can use the libref and data set with any other SAS procedure. This statement prints
the Staff table:
PROC PRINT DATA=mymdb.staff;
RUN;
This statement associates the SAS libref MYXLS with an Excel workbook:
LIBNAME myxls 'c:\demo.xls';
See Also
“LIBNAME Statement” on page 147
103
Chapter 10
Data Set Options
Dictionary
AUTOCOMMIT
Determines whether the ACCESS engine commits (saves) updates as soon as you submit them.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
AUTOCOMMIT=YES | NO
Syntax Description
YES
specifies that updates are committed to a table as soon as they are submitted, and no
rollback is possible.
NO
specifies that the SAS/ACCESS engine automatically performs the commit when it
reaches the end of the file.
COMMAND_TIMEOUT
Specifies the number of seconds to wait before a command times out.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
See: To assign this option to a group of tables, use the COMMAND_TIMEOUT option
specified in “LIBNAME Options” on page 121.
Syntax
COMMAND_TIMEOUT= number-of-seconds
Syntax Description
number-of-seconds
the number of seconds to wait before a command times out.
DBCOMMIT 105
CURSOR_TYPE
Specifies the cursor type for read-only cursors and for cursors to be updated.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
Syntax
CURSOR_TYPE=KEYSET_DRIVEN | STATIC
Syntax Description
KEYSET_DRIVEN
specifies that the cursor determines which rows belong to the result set when the
cursor is opened. However, changes that are made to these rows are reflected as you
move the cursor.
STATIC
specifies that the cursor builds the complete result set when the cursor is opened. No
changes made to the rows in the result set after the cursor is opened are reflected in
the cursor. Static cursors are read-only.
Details
By default, this option is not set, and the Microsoft Jet provider uses a default. The OLE
DB properties applied to an open row set are as follows:
KEYSET_ DBPROP_OTHERINSERT=FALSE,
DRIVEN DBPROP_OTHERUPDATEDELETE=TRUE
STATIC DBPROP_OTHERINSERT=FALSE,
DBPROP_OTHERUPDATEDELETE=FALSE
See your OLE DB programmer reference documentation for details about these
properties.
See Also
To assign this option to a group of tables, use the CURSOR_TYPE option specified in
“LIBNAME Options” on page 121.
DBCOMMIT
Enables you to issue a commit statement automatically after a specified number of rows have been
processed.
106 Chapter 10 • Data Set Options
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option default: 1000
Syntax
DBCOMMIT=number-of-rows
Syntax Description
number-of-rows
is an integer greater than or equal to 0.
Details
DBCOMMIT affects update, delete, and insert processing. The number of rows
processed includes rows that are not processed successfully. When DBCOMMIT=0, a
commit is issued only once after the procedure or DATA step completes.
If the DBCOMMIT option is explicitly set, SAS/ACCESS fails any update that has a
WHERE clause.
Note: If you specify the DBCOMMIT= option and the ERRLIMIT= option, and these
options collide during processing, then the DBCOMMIT= option is issued first and
the rollback is issued second. Because the DBCOMMIT= option is issued before the
ERRLIMIT= option, the DBCOMMIT= option overrides the ERRLIMIT= option in
this situation.
See Also
• “ERRLIMIT” on page 115
• “LIBNAME Options” on page 121
DBCONDITION
Specifies criteria for subsetting and ordering data.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBCONDITION=SQL-query-clause
DBFORCE 107
Syntax Description
SQL-query-clause
is a data source-specific SQL query clause, such as WHERE, GROUP BY,
HAVING, or ORDER BY.
Details
This option enables you to specify selection criteria in the form of data source-specific
SQL query clauses, which the SAS/ACCESS engine passes directly to the data source
for processing. When selection criteria are passed directly to the data source for
processing, performance is often enhanced. The data source checks the criteria for
syntax errors when it receives the SQL query.
The option is ignored when you use DBCONDITION.
See Also
“DBKEY” on page 109
DBCREATE_TABLE_OPTS
Specifies data source-specific syntax to add to the CREATE TABLE statement.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
DBCREATE_TABLE_OPTS='SQL-clauses'
Syntax Description
SQL-clauses
are one or more data source-specific clauses that can be appended to the end of an
SQL CREATE TABLE statement.
Details
This option enables you to add data source-specific clauses to the end of the SQL
CREATE TABLE statement. The SAS/ACCESS engine passes the SQL CREATE
TABLE statement and its clauses to the data source, which executes the statement and
creates the table.
See Also
To assign this option to a group of tables, use the DBCREATE_TABLE_OPTS= option
specified in “LIBNAME Options” on page 121.
DBFORCE
Specifies whether to force the truncation of data during insert processing.
Valid in: DATA and PROC steps
108 Chapter 10 • Data Set Options
Default: NO
Syntax
DBFORCE= YES | NO
Syntax Description
YES
specifies that the rows that contain data values that exceed the length of the column
are inserted, and the data values are truncated to fit the column width.
NO
specifies that the rows that contain data values that exceed the column length are not
inserted.
Details
This option determines how the SAS/ACCESS engine handles rows that contain data
values that exceed the length of the column.
The SAS data set option FORCE= overrides this option when it is used with PROC
APPEND or the PROC SQL UPDATE statement. The PROC SQL UPDATE statement
does not provide a warning before truncating the data.
DBGEN_NAME
Specifies whether to rename columns automatically when they contain disallowed characters.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
Syntax
DBGEN_NAME=DBMS | SAS
Syntax Description
DBMS
specifies that disallowed characters are converted to underscores.
SAS
specifies that columns that contain disallowed characters are converted into valid
SAS variable names, using the format _COLn, where n is the column number
(starting with zero). If a name is converted to a name that already exists, a sequence
number is appended to the end of the new name.
Details
SAS retains column names when reading data, unless a column name contains characters
that SAS does not allow, such as $ or @. SAS allows alphanumeric characters and the
underscore (_).
DBLABEL 109
This option is intended primarily for National Language Support. Notably the
conversion of kanji to English characters. The English characters converted from kanji
are often not allowed in SAS. If you specify DBGEN_NAME=SAS, a column named
DEPT$AMT is renamed to _COLn where n is the column number. If you specify
DBGEN_NAME=DBMS, a column named DEPT$AMT is renamed to DEPT_AMT.
See Also
To assign this option to a group of tables, use the DBGEN_NAME option specified in
“LIBNAME Options” on page 121.
DBKEY
Improves performance for a join with a large source table and a small SAS data set (specifies a column to
use as an index).
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBKEY=<('column-1' ... 'column-n')>
Syntax Description
column
is the name of the column that forms the index on the data source table.
Details
When processing a join that involves a large data source table and a relatively small SAS
data set, you might be able to use DBKEY to improve performance.
CAUTION:
Improper use of this option can harm performance.
DBLABEL
Specifies whether to use SAS variable labels as data source column names during output processing.
Valid in: DATA and PROC steps
Default: NO
Syntax
DBLABEL=YES | NO
110 Chapter 10 • Data Set Options
Syntax Description
YES
specifies that SAS variable labels are used as data source column names during
output processing.
NO
specifies that SAS variable names are used as data source column names.
Details
This option is valid only for creating data source tables.
Note: Only up to 64 characters of SAS variable labels are written to a Microsoft Access
or a Microsoft Excel file.
DBMAX_TEXT
Determines the length of a very long data source character data type that is read into SAS or written from
SAS when you are using a SAS/ACCESS engine.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
DBMAX_TEXT=integer
Syntax Description
integer
is a number between 1 and 32,767.
Details
This option applies to reading, appending, and updating rows in an existing table. It does
not apply when you are creating a table.
DBNULL 111
See Also
To assign this option to a group of tables, use the DBMAX_TEXT= option specified in
“LIBNAME Options” on page 121.
DBNULL
Specifies whether NULL is a valid value for the specified columns when a table is created.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: YES
Syntax
DBNULL=
(<column-name-1> =YES|NO
<column-name-n> =YES|NO
<_ALL_> =YES|NO)
Syntax Description
YES
specifies that a NULL value is valid for the specified columns.
NO
specifies that a NULL value is not valid for the specified columns.
Details
this option is valid only for creating data source tables. If you specify more than one
column name, the names must be separated with spaces.
The DBNULL= option processes values from left to right. If you specify a column name
twice, or if you use the _ALL_ value, the last value overrides the first value specified for
the column.
Note: only the Access engine supports this option. The Excel engine does not support
this option.
In this example, all columns in the new MyDBLib.MyDept3 table except for the Jobcode
column are prevented from accepting null values. If the Employees table contains any
null values in any column other than the Jobcode column, the DATA step fails.
DATA mydblib.mydept3(DBNULLl=(_ALL_=no jobcode=YES));
SET mydblib.employees;
RUN;
DBNULLKEYS
Controls the format of the WHERE clause when you use the DBKEY data set option.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME setting
Syntax
DBNULLKEYS= YES | NO
Details
If there might be NULL values in the transaction table or the master table for the
columns that you specify in the DBKEY option, use DBNULLKEYS=YES. When you
specify DBNULLKEYS=YES, and specify a column that is not defined as DBKEY=
NOT NULL, SAS generates a WHERE clause that finds NULL values.
If you specify DBKEY=COLUMN and COLUMN is not defined as NOT NULL, SAS
generates a WHERE clause.
Example:
WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)));
SAS generates the WHERE clause once and uses it for any value, NULL, or NOT
NULL in the column. This syntax can be much less efficient than the shorter form of the
WHERE clause. When you specify DBNULLKEYS=NO, or specify a column that is
NOT NULL in the DBKEY= option, SAS generates a simple WHERE clause.
If there are no NULL values in the transaction or master table for the columns, use
DBNULLKEYS=NO. If you specify DBNULLKEYS=NO and DBKEY=COLUMN,
SAS generates a shorter form of the WHERE clause. SAS generates the WHERE clause
even if the column DBKEY specifies is defined as NOT NULL.
WHERE (COLUMN = ?)
See Also
• “DBKEY” on page 109
• “LIBNAME Options” on page 121
DBSASLABEL
Specifies whether SAS/ACCESS saves the data source's column names as SAS label names.
DBSASTYPE 113
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: COMPAT
Syntax
DBSASLABEL= COMPAT | NONE
Syntax Description
COMPAT
specifies that SAS/ACCESS saves the data source's column names as SAS label
names. This is compatible to the previous SAS releases.
NONE
specifies that SAS/ACCESS does not save the data source's column names as SAS
label names. SAS label names are left as NULLs.
Details
This option is valid only while you are writing data into SAS from a data source.
DBSASTYPE
Specifies data type(s) to override the default SAS data type(s) during input processing of data.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBSASTYPE=(<column-name-1> =<SAS data-type> ...<column-name-n> =
<SAS data-type> )
Syntax Description
column-name
specifies a data source column name.
SAS data-type
specifies a SAS data type. SAS data types include CHAR(n), NUMERIC,
DATETIME, DATE, TIME.
Details
By default, SAS/ACCESS converts each data source data type to a SAS data type during
input processing. When you need a different data type, you can use this option to
override the default and assign a SAS data type to each specified data source column.
Note: Some conversions might not be supported. If a conversion is not supported, SAS
prints an error to the log.
114 Chapter 10 • Data Set Options
DBTYPE
Specifies a data type to use instead of the default data source data type when SAS creates a data source
table.
Valid in: DATA and PROC steps
Default: none
Syntax
DBTYPE=(<column-name-1> =<data-source-type> ...
<column-name-1> =<data-source-type> )
Syntax Description
column-name
specifies a data source column name.
data-source-type
specifies a data source data type. See the documentation for your SAS/ACCESS
interface for the default data types for your data source.
Details
By default, SAS/ACCESS converts each SAS data type to a predetermined data source
data type when it writes data to your data source. When you need a different data type,
use DBTYPE= to override the default data type chosen by the SAS/ACCESS engine.
DBTYPE
Specifies a data type to use instead of the default data source data type when SAS creates a data source
table.
Valid in: DATA and PROC steps
Default: none
Syntax
DBTYPE=(<column-name-1> =<data-source-type> ...
<column-name-1> =<data-source-type> )
ERRLIMIT 115
Syntax Description
column-name
specifies a data source column name.
data-source-type
specifies a data source data type. See the documentation for your SAS/ACCESS
interface for the default data types for your data source.
Details
By default, SAS/ACCESS converts each SAS data type to a predetermined data source
data type when it writes data to your data source. When you need a different data type,
use DBTYPE= to override the default data type chosen by the SAS/ACCESS engine.
ERRLIMIT
Specifies the number of errors that are allowed before SAS stops processing and issues a rollback.
Valid in: DATA and PROC steps
Default: 1
Syntax
ERRLIMIT=integer
Syntax Description
INTEGER
is a positive integer that represents the number of errors after which SAS stops
processing and issues a rollback.
Details
SAS calls the data source to issue a rollback after a specified number of errors occurs
during the processing of inserts, deletes, updates, and appends. If ERRLIMIT= is set to
0, SAS processes all rows, regardless of the number of errors that occur. The SAS log
displays the total number of rows processed and the number of failed rows, if applicable.
The DBCOMMIT= option overrides the ERRLIMIT= option. If you specify a nonzero
value for the DBCOMMIT= option, rollbacks affected by the ERRLIMIT= option might
not be complete. Records already committed by DBCOMMIT= option are not processed
again.
Note: This option cannot be used from a SAS client session in a SAS/SHARE
environment.
116 Chapter 10 • Data Set Options
See Also
“DBCOMMIT” on page 105
INSERT_SQL
Determines the method to use to insert rows into a data source.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
INSERT_SQL=YES | NO
Syntax Description
YES
specifies that the SAS/ACCESS engine uses the data source's SQL insert method to
insert new rows into a table.
NO
specifies that the SAS/ACCESS engine uses an alternate (data source-specific)
method to add new rows to a table.
See Also
To assign this option to a group of tables, use the INSERT_SQL= option specified in
“LIBNAME Options” on page 121.
INSERTBUFF
Specifies the number of rows in a single insert.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
INSERTBUFF=number-of-rows
NULLCHAR 117
Syntax Description
number-of-rows
specifies the number of rows to insert. The value must be a positive integer.
Details
SAS allows the maximum number of rows that is allowed by the data source. The
optimal value for this option varies with factors such as network type and available
memory. You might need to experiment with different values to determine the best value
for your site.
When you assign a value greater than INSERTBUFF=1, the SAS notes indicating
success or failure of the insert operation might be incorrect. These notes are generated
for a single insert. This is also true, when multiple inserts are performed.
Note: PC Files Server does not support INSERTBUFF= option with a value higher than
1 for writing data to Excel. It ignores this option when writing data to Excel.
If the DBCOMMIT= option is specified with a value that is less than the value of
INSERTBUFF=, then DBCOMMIT= overrides INSERTBUFF= option.
Note: When you are inserting with the VIEWTABLE window or the FSEDIT or
FSVIEW procedure, use INSERTBUFF=1 to prevent the data source interface from
trying to insert multiple rows. These features do not support inserting more than one
row at a time.
See Also
• “DBCOMMIT” on page 105
• “Overview of Data Set Options” on page 103
NULLCHAR
Indicates how SAS character missing values are handled during insert, update, and DBKEY= processing.
Valid in: DATA and PROC steps
Default: SAS
Syntax
NULLCHAR= YES | NO
Syntax Description
YES
indicates that character missing values in SAS data sets are treated as NULL values
if the data source allows them. Otherwise, an error is returned.
NO
indicates that character missing values in SAS data sets are treated as the
NULLCHARVAL= value, regardless of whether the data source allows NULLs for
the column.
118 Chapter 10 • Data Set Options
Details
This option affects insert and update processing and also applies when you use the
DBKEY= option.
in conjunction with the NULLCHARVAL= data set option, NULLCHARVAL=
determines what is inserted when NULL values are not allowed.
All SAS numeric missing values (represented in SAS as .) are treated by the data source
as NULLs.
See Also
“DBKEY” on page 109
NULLCHARVAL
Defines the character string that replaces SAS character missing values during insert, update, and
DBKEY= processing.
Valid in: DATA and PROC steps
Default: a blank character
Syntax
NULLCHARVAL=<'character-string'>
Details
This option affects insert and update processing and also applies when you use the
option.
This option works with the NULLCHAR= option. NULCHAR= determines whether a
SAS character NULL value is treated as a NULL value.
If NULLCHARVAL= is longer than the maximum column width, one of these actions
occurs:
• The string is truncated if DBFORCE=YES.
• The operation fails if DBFORCE=NO.
See Also
"DBKEY=" on page 109
READBUFF
Specifies the number of rows of data to read into the buffer.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
SASDATEFMT 119
Syntax
READBUFF=<number-of-rows>
Syntax Description
number-of-rows
is the maximum value that is allowed by the data source.
Details
This option improves performance by specifying a number of rows that can be held in
memory for input into SAS. Buffering data reads can decrease network activities and
increase performance. Because SAS stores the rows in memory, higher values for
READBUFF= use more memory. If too many rows are selected at once, then the rows
that are returned to the SAS application can be out of date.
When READBUFF=1, only one row is retrieved at a time. The higher the value for
READBUFF=, the more rows the SAS/ACCESS engine retrieves in one fetch operation.
ROWSET_SIZE is an alias for this option.
See Also
To assign this option to a group of tables, use the READBUFF= option as specified in
“LIBNAME Options” on page 121.
SASDATEFMT
Changes the SAS date format of a data source column.
Valid in: DATA and PROC steps
Default: none
Syntax
SASDATEFMT=(<data-source-date-column-1> =<SAS date-format> ...
<data-source-date-column-n> =<SAS date-format> )
Syntax Description
data-source-date-column
specifies the name of a date column in a data source table.
SAS date-format
specifies a SAS date format that has an equivalent informat. For example,
DATETIME21.2 is both a SAS format and informat, so it is valid for the SAS date-
format argument.
Details
If the date format of a SAS column does not match the date format of the corresponding
data column, convert the SAS date values to appropriate values. The SAS DATEFMT=
option enables you to convert date values from a SAS date format to different SAS date
format.
120 Chapter 10 • Data Set Options
Use SAS DATEFMT= to prevent date type mismatches under these circumstances:
• during input operations to convert data source date values to the correct SAS DATE,
TIME, or DATETIME values
• during output operations to convert SAS DATE, TIME, or DATETIME values to the
correct data source date values
If the SAS date format and the data source date format match, this option is not needed.
The default SAS date format is data source-specific and is determined by the data type of
the data source column. See the documentation for your SAS/ACCESS interface.
Note: For non-English date types, SAS automatically converts the data to the SAS type
of NUMBER. The SAS DATEFMT= option does not currently handle these date
types. You can use a PROC SQL view to convert the source data to a SAS date
format, as you retrieve the data. You can also use a format statement in other
contexts.
121
Chapter 11
LIBNAME Options
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
LIBNAME Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Dictionary
LIBNAME Options
provides additional control over the way that SAS processes PC files data.
Interaction: For many tasks that you perform, you do not need to specify any of these advanced
options. Many of these options are also available as data set options.
Syntax
Optional Arguments
ACCESS= READONLY
indicates that tables and views can be read but not updated.
AUTOCOMMIT= YES | NO
specifies whether the ACCESS engine commits updates when submitted.
YES specifies that updates are committed to a table as soon as they are submitted.
No rollback is possible.
NO specifies that updates are committed when SAS reaches the end of the file.
COMMAND_TIMEOUT= number-of-seconds
specifies the number of seconds that pass before a data source command times out.
Alias: TIMEOUT
Default: 0 (no time-out)
SHAREDREAD specifies that all READ operations that access data source tables in a
single libref share a single connection. A separate connection is established for each
table that is opened for update or output operations.
Where available, this is usually the default value because it offers the best
performance and it guarantees data integrity.
UNIQUE specifies that a separate connection is established every time a data source
table is accessed by a SAS application.
GLOBALREAD specifies that all READ operations that access data source tables
with multiple librefs, share a single connection if the librefs are created by
LIBNAME statements that specify:
• identical values for the CONNECTION= option
• identical values for the CONNECTION_GROUP= option
• identical values for all data source connection options
A separate connection is established for each table that is opened for update or
output operations.
Default: SHAREDREAD
See: CONNECTION_GROUP on page 122
CONNECTION_GROUP
specifies that operations against multiple LIBREFS share a single connection to the
data source. Also specifies that operations against multiple pass-through facility
CONNECT statements share a single connection to the data source.
CURSOR_TYPE= KEYSET_DRIVEN | STATIC
specifies the cursor type for read-only cursors and for cursors to be updated. If you
do not set CURSOR_TYPE= , the Jet provider that you are using determines the
default.
KEYSET_DRIVEN specifies that the cursor determines which rows belong to the
result set when you open the cursor. Changes that are made to these rows are
reflected as you move the cursor. The OLE DB property
DBPROP_OTHERUPDATEDELETE= TRUE for key set driven cursors.
STATIC specifies that the complete result set is built when you open the cursor. No
changes that are made to the result set are reflected in the cursor. Static cursors are
read-only. The OLE DB property DBPROP_OTHERUPDATEDELETE= FALSE
for static cursors.
Alias: CURSOR
DBCOMMIT= number-of-rows
affects update, delete, and insert processing. The number of rows that are processed
includes rows that are not processed successfully. If you set DBCOMMIT= 0, a
commit is issued only once (after the procedure or DATA step completes). If the
DBCOMMIT= option is explicitly set, SAS/ACCESS fails any update that has a
WHERE clause.
Default: 1,000 [inserting]
0 [updating; commit occurs when data set or procedure completes]
Note: If you specify both DBCOMMIT= and ERRLIMIT= options, and these
options collide during processing, DBCOMMIT= is issued first and ERRLIMIT=
is issued second. Because the DBCOMMIT= option is issued before the
ERRLIMIT= option, the DBCOMMIT= option overrides the ERRLIMIT=
option in this situation.
LIBNAME Options 123
This syntax enables SAS to prepare the statement once and use it for any (NULL or
NOT NULL) in the column.
Note: This syntax has the potential to be much less efficient than the shorter form
the WHERE clause presented below.
In the DBKEY= option, and there might be NULL values in a column, specify
DBNULLKEYS= YES. SAS generates a WHERE clause to find NULL values. If
you do either of the following steps:
• specify DBNULLKEYS= YES and a column not defined NOT
DBNULLKEYS= data set option, SAS generates a WHERE clause to find
NULL values.
• specify DBKEY= and COLUMN is not defined as NOT NULL, SAS generates a
WHERE clause similar to the following:
WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)));
NO If you:
• specify DBNULLKEYS=NO or specify a column that is defined as NOT NULL
in the DBKEY= option, SAS generates a simple WHERE clause.
124 Chapter 11 • LIBNAME Options
• know that there are no NULL values in the transaction or the master table for the
columns specified in the DBKEY= option, use DBNULLKEYS=NO.
• specify DBNULLKEYS=NO and specify DBKEY=COLUMN, SAS generates a
shorter form of a WHERE clause. The WHERE clause is generated whether the
column that DBKEY= is defined as NOT NULL.
Default: YES
Note: This syntax enables SAS to prepare the statement once and use it for any
value, NULL, or NOT NULL in the column.
Example:
Example WHERE (COLUMN = ?)
DEFER= NO | YES
specifies when a connection to the data source occurs.
NO specifies that the connection to the data source occurs when the libref is assigned
by a LIBNAME statement.
YES specifies that the connection to the data source occurs when a table in the data
source is opened.
Default: NO
• NOWHERE prevents WHERE clauses from being passed to the data source for
processing. This includes SAS WHERE clauses and PROC SQL generated or
PROC SQL specified WHERE clauses.
Default: YES
Restriction: The NOMULTOUTJOINS option does not affect outer joins of two
tables.
Note: The NOMULTOUTJOINS option is always set for the Microsoft Jet engine.
FILELOCK= YES | NO
specifies the access level to a Microsoft Excel file. By default, FILELOCK is not set.
Specifying FILELOCK= YES indicates that the LIBNAME engine checks and
denies a connection if the file was opened by Excel or another application.
CAUTION:
SAS does not check whether the Excel file was opened by Excel or another
application when you assign a LIBNAME statement for the file. A potential
access violation can occur if a user attempts to update the Excel file using
Microsoft Excel.
YES allows only one LIBNAME assignment with READ and WRITE permission to
connect to the file. The LIBNAME assignment is denied if the file has been opened
by Excel or any other application.
NO specifies that the Microsoft Excel LIBNAME engine behaves the same as in
SAS 9.1.
By setting FILELOCK= YES with ACCESS= READONLY, this enables other
applications to open the Excel file in READONLY mode with connection
information set to browse data.
Restriction: Applies only to the Microsoft Excel LIBNAME engine; has no effect
on the Microsoft Access LIBNAME engine.
INSERT_SQL= YES | NO
specifies the method that is used to insert rows into a data source.
YES specifies that the SAS/ACCESS engine uses the data source's SQL insert
method to insert rows into a table.
NO specifies that the SAS/ACCESS engine uses an alternate (data source-specific)
method to add rows to a table.
Default: NO
INSERTBUFF= number-of-rows
specifies the number of rows for a multi-row insert. If the INSERTBUFF value is
greater than the DBCOMMIT value, the DBCOMMIT value overrides the
INSERTBUFF value. The value for INSERTBUFF= must be a positive number.
Default: 1
Note: If you assign a value that is greater than INSERTBUFF= 1, the information
written to the log indicating the success or failure might be incorrect. SAS only
writes information for a single insert, even when multiple inserts are performed.
MSENGINE= ACE | JET
specifies the database engine used for accessing the Microsoft Excel file or the
Microsoft Access database. The Microsoft Jet engine is older and supports formats
up to 2003. The Microsoft Ace engine supports 2007 and later formats.
Default: ACE
Restriction: It is recommended that you do not use this file option unless you are
trying to create a 95 format file.
126 Chapter 11 • LIBNAME Options
PREPARE= YES | NO
NO forces the engine to execute the SQL statement before the Describe action. If you
have a linked table to a text file this ensures that the table is found.
Default: YES
READBUFF= number-of-rows
specifies the number of rows of data to read. Setting a higher value for this option
reduces I/O and increases performance, and memory usage. If too many rows are
read at once, values returned to SAS might be out of date.
Alias: ROWSET | ROWSET_SIZE
Default: 1
SCANTEXT= YES | NO
specifies whether to scan the length of text data for a data source column and use the
length of the longest data string as the SAS column width. For Microsoft Excel, this
option applies to all character data type columns. For Microsoft Access, this option
only applies to the MEMO data type field, it does not apply to the TEXT (less than
256 characters long) field.
YES scans the length of text data for a data source column. Sets the length of the
longest data string as the SAS variable length. If the maximum SCAN_TEXT=
length is greater than the maximum DBMAX_TEXT= length, the DBMAX_TEXT=
value is set as the SAS variable length. Default for Microsoft Excel workbook.
NO specifies that the column length that is returned from the Microsoft Jet provider
is set as the SAS variable length. If the length that is returned from the Microsoft Jet
provider is greater than the DBMAX_TEXT= value, the smaller value is set as the
SAS variable length. Specify SCANTEXT= NO when you need to update data in a
Microsoft Access database or a Microsoft Excel workbook.
Alias: SCAN_TEXT | SCANMEMO | SCAN_TEXTSIZE
SPOOL= YES | NO
specifies whether SAS creates a utility spool file during read transactions that read
data more than once.
YES specifies that SAS creates a utility spool file into which it writes the rows that
are read the first time. For subsequent passes through the data, the rows are read
from the utility spool file rather than being reread from the data source table. This
guarantees that the row set is the same for every pass through the data
NO specifies that the required rows for all passes of the data are read from the data
source table. The row set might not be the same for each pass through the data.
Default: YES
LIBNAME Options 127
STRINGDATES= YES | NO
specifies whether datetime values are read from the data source as character strings
or as numeric date values. STRINGDATES is not available as a data set option.
YES specifies that SAS/ACCESS reads datetime values as character strings.
NO specifies that SAS/ACCESS reads datetime values as numeric date values.
Alias: STRDATES
Default: NO
UNICODE= YES | NO
determines whether the LIBNAME engine binds the character data type columns
with narrow or wide character mode.
This option supersedes the DBENCODING option. For DBCS (Chinese, Korean,
and Japanese) use, it is recommended to use this option instead of the
DBENCODING= option.
YES specifies that SAS binds the character type columns with wide character mode.
This allows some character data such as DBCS to be returned correctly. This setting
works the same as setting DBENCODING='UTF-16'.
NO specifies that SAS binds the character type columns with narrow character mode.
Default: NO
USEDATE= YES | NO
specifies whether to assign the DATE. format or the DATETIME. format for
datetime columns in the data source table while importing data from a Microsoft
Access database or a Microsoft Excel workbook.
YES specifies that the DATE. format is assigned to datetime columns in the data
source table.
NO specifies that the DATETIME. format is assigned for datetime columns in the
data source table.
Alias: USE_DATE | USE_DATETYPE
Default: YES for Microsoft Excel workbooks.
NO for Microsoft Access databases.
128 Chapter 11 • LIBNAME Options
129
Chapter 12
Pass-Through Facility for Access
and Excel on Microsoft Windows
specify in the CONNECT statement are stored with the view. Therefore, when the view
is used in a SAS program, SAS can establish the appropriate connection to the data
source.
The following sections present the syntax for the pass-through facility statements and the
CONNECTION TO component. You can use this component with the PROC SQL
SELECT statement to query data from a data source.
Dictionary
SQL Procedure
Implements the Structured Query Language for SAS.
See: Base SAS Procedures Guide
SAS SQL Procedure User's Guide
SAS SQL Query Window User's Guide
Syntax
PROC SQL <options-list>
CONNECT TO data-source-name AS <alias> <(connect-statement-arguments)> ,
<(database-connection-arguments)>
DISCONNECT FROM <data-source-name> <alias>
EXECUTE (data-source-specific-SQL-statement)
BY
<data-source-name> <alias>
SELECT column-list
FROM
CONNECTION TO data source-name
AS
<alias> <database-connection-arguments;>
Without Arguments
Use the CONNECT TO statement with the SQL procedure to query data from a data
source.
Details
Return Codes
As you use the PROC SQL statements that are available in the pass-through facility, any
error conditions are written to the SAS log. The pass-through facility generates return
codes and messages that are available to you through these SAS macro variables:
SQLXRC
contains the data source return code that identifies the data source error.
CONNECT Statement 131
SQLXMSG
contains descriptive information about the data source error that is generated by the
data source.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the
SAS log using the %PUT macro. The contents are reset after each pass-through facility
statement is executed.
CONNECT Statement
Establishes a connection with the data source.
Valid in: PROC SQL statement
Syntax
CONNECT TO data-source-name
CONNECT TO option(s)
Optional Arguments
data-source-name
Specifies the data source to which you want to connect. Because this method
requires connecting through a PC Files Server, you must use PCFILES as your data
source. You can also specify an optional alias in the CONNECT statement.
alias
specifies an optional alias for the connection that has 1 to 32 characters. If you
specify an alias, the keyword AS must appear before the alias. If an alias is not
specified, the data source name is used as the name of the pass-through connection.
connect-statement-arguments
specifies arguments that indicate whether you can make multiple connections (shared
connections, unique connections, and so on) to the database.
database-connection-arguments
specifies the data source-specific arguments that are needed by PROC SQL to
connect to the data source. These arguments are not required. The default behavior
opens a dialog box with prompts to specify connection information.
132 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
Details
Overview
The CONNECT statement establishes a connection with the data source. You establish a
connection to send data source-specific SQL statements to the data source or to retrieve
data source data. The connection remains in effect until you issue a DISCONNECT
statement or terminate the SQL procedure. See “DISCONNECT Statement” on page
137.
To connect to a data source using the pass-through facility, complete the following steps:
1. Initiate a PROC SQL step.
2. Use the pass-through facility CONNECT statement with the PC files engine name
and then assign an alias if you want.
3. Specify any arguments needed to connect to the database.
4. Specify any attributes for the connection.
The CONNECT statement is optional for some data sources. However, if you do not
specify it, default values for all database connection arguments are used.
Any return code or message that is generated by the data source is available in the macro
variables SQLXRC and SQLXMSG after the statement executes. See “Return Codes” on
page 130 for more information about these macro variables.
SERVER= pc-server-host-name
specifies the computer name of the PC on which you started the PC Files Server.
This name is required by UNIX users to connect to this server machine and is
CONNECT Statement 133
reflected on the server control panel. This is a required field when connecting to the
PC Files Server for data.
You can specify this host name as a simple computer name (for example, wxp320), a
fully qualified network name (for example, wxp320.domain.com), or an IP
address.
Note: Omitting the SERVER= option on Microsoft Windows clients invokes
Autostart.
SERVERUSER= 'domain\server-user-name'
specifies the domain name and User ID for the PC running PC Files Server. Always
enclose the value in quotation marks. Otherwise, the backslash can be misinterpreted
by the SAS parser.
Alias: SERVERUID
Notes:
If you are not on a domain, omit the domain name and the backslash.
Use the USER= option for database user IDs.
SERVERPASS= 'server-user-password'
specifies the password for the PC Files Server for the user ID given. If the account
has no password, omit this option. Always enclose the value in quotes in order to
preserve the case of the password.
Alias: SERVERPASSWORD | SERVERPW | SERVERPWD
Notes:
Passwords are generally case sensitive.
Use the PASSWORD= option for database passwords.
SSPI= YES | NO
enables the PC Files Server to allow Integrated Windows Authentication. This is a
mechanism for the Windows client and server to exchange credentials.
Default: NO
Restriction: Microsoft Windows 64-Bit only.
Note: SSPI can also be enabled by specifying the –SSPI option on the SAS
command line.
DBPASSWORD= database-password
enables you to access your file if you have database-level security set in your MDB
file. A database password is case sensitive, and you can define it instead of user-level
security.
Restriction: Microsoft Access only.
DBSYSFILE= workgroup-information-file
contains information about the users in a workgroup based on information that you
define for your Microsoft Access database. Any user and group accounts or
passwords that you create are saved in the new workgroup information file.
PASSWORD= user-password
specifies a password for the user account, if required by the data source. Passwords
are case sensitive.
MSENGINE= ACE | JET
determines the database engine used for accessing the Microsoft Excel file or
Microsoft Access database. The Microsoft Jet engine is older and supports formats
up to 2003. The Microsoft ACE engine supports Microsoft Excel 2007 and Microsoft
Access 2007 and older formats.
Default: ACE
134 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
USER= User ID
specifies a default user account name. The default value is Admin. User names can
be 1 to 20 characters long and can include alphabetic characters, accented characters,
numbers, and spaces. If you have user-level security set in your MDB file, you need
to use this option and the PASSWORD= option to access your file.
VERSION= 2007 | 2003 | 2002 | 2000 | 97 | 95 | 5
sets the version of Microsoft Excel workbook. The default value is 97.
Alias: VER
Restriction: Microsoft Excel only.
Note: You do not need to specify this option for an existing Microsoft Excel file. If
you want to create a new Microsoft Excel workbook file, you can use this option
to specify the version that you want to create. Note that versions 97, 2000, and
2003 of Excel share the same file format. Versions 95 and 5 share a separate file
format.
COMMAND_TIMEOUT= number-of-seconds
specifies the number of seconds before a data source command times out.
Alias: TIMEOUT
Default: 0 (no time-out)
CONNECTION=SHARED | GLOBAL
specifies whether multiple CONNECT statements for a data source can use the same
connection. The CONNECTION= option enables you to control the number of
connections, and therefore transactions, that your SAS/ACCESS engine executes and
supports for each CONNECT statement.
SHARED
specifies that the CONNECT statement makes one connection to the DBMS.
Only pass-through statements that use this alias share the connection.
GLOBAL
specifies that multiple CONNECT statements can share the same connection to
the DBMS.
• The CONNECT statements must use identical values for the
CONNECTION= option.
CONNECT Statement 135
CONNECTION_GROUP= connection-group
causes operations against multiple librefs to share a connection to the data source.
Also causes operations against multiple pass-through facility CONNECT statements
to share a connection to the data source.
CURSOR_TYPE= DYNAMIC | FORWARD_ONLY | KEYSET_DRIVEN | STATIC
specifies the cursor type for read-only cursors and for cursors to be updated.
DYNAMIC
specifies that the cursor reflects all changes that are made to the rows in a result
set as you move the cursor. The data values and the membership of rows in the
cursor can change dynamically on each fetch. This is the default for the DB2
UNIX, PC files, and Microsoft SQL Server interfaces.
FORWARD_ONLY
specifies that the cursor behaves like a DYNAMIC cursor, except that it supports
only fetching the rows sequentially.
KEYSET_DRIVEN
specifies that the cursor determines which rows belong to the result set when the
cursor is opened. However, changes that are made to these rows are reflected as
you scroll around the cursor.
STATIC
specifies that the complete result set is built when the cursor is opened. No
changes that are made to the rows in the result set after the cursor is opened are
reflected in the cursor. Static cursors are read-only.
Alias: CURSOR
Default: None
DBMAX_TEXT= n
specifies an integer between 1 and 32,767 that indicates the maximum length for a
character string. Longer character strings are truncated. This option applies only
when you are reading, appending, and updating Microsoft Access or Excel character
data from SAS.
Default: 1,024
Note: Although you can specify a value less than 256, it is not recommended.
136 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
DEFER= NO | YES
enables you to specify when the CONNECT statement occurs.
NO
specifies that the connection to the data source occurs when the libref is assigned
by a LIBNAME statement.
YES
specifies that the connection to the data source occurs when a table in the data
source is opened.
Default: NO
READBUFF= number-of-rows
specifies the number of rows to use when you are reading data from a data source.
Setting a higher value for this option reduces I/O and increases performance, but also
increases memory usage. In addition, if too many rows are read at once, values
returned to SAS might be out of date.
Alias:
ROWSET=
ROWSET_SIZE=
Default: 1
STRINGDATES= YES | NO
specifies whether datetime values are read from the data source as character strings
or as numeric date values. STRINGDATES= is not available as a data set option.
YES
specifies that SAS/ACCESS reads datetime values as character strings.
NO
specifies that SAS/ACCESS reads datetime values as numeric date values.
Alias: STRDATES
Default: NO
USEDATE= YES | NO
specifies whether to assign the DATE. format or the DATETIME. format for
datetime columns in the data source table while importing data from a Microsoft
Access database or a Microsoft Excel workbook.
YES
specifies that the DATE. format is assigned to datetime columns in the data
source table.
NO
specifies that the DATETIME. format is assigned for datetime columns in the
data source table.
Alias: USE_DATE | USE_DATETYPE
Default: NO
Example
The following example uses the CONNECT statement with the PATH= option to
connect to the Microsoft Access database file, c:\demo.mdb:
PROC SQL;
CONNECT TO PCFILES AS db (SERVER=d2323 PATH=' c:\demo.mdb' );
EXECUTE Statement 137
DISCONNECT Statement
Ends the connection to the data source.
Valid in: SQL procedure.
Syntax
DISCONNECT FROM <data-source-name> <alias>
Syntax Description
Data-source-name
specifies the data-source-name from which you want to disconnect. The
DISCONNECT statement's data-source-name must match the data-source-name that
you specified in the CONNECT statement.
Alias
specifies the data source alias from which you want to disconnect. The
DISCONNECT statement's alias must match the alias that you specified in the
CONNECT statement.
Details
The DISCONNECT statement ends the connection with the data source. If the
DISCONNECT statement is omitted, an implicit DISCONNECT is performed when the
procedure ends. The SQL procedure continues to execute until you submit a QUIT
statement, a SAS procedure, or a DATA step.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the
SAS log using the macro. The contents are reset after each pass-through facility
statement is executed.
See “Return Codes” on page 130 for additional information.
EXECUTE Statement
Sends data source-specific, non-query SQL statements to the data source.
Valid in: SQL procedure steps.
138 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
Syntax
EXECUTE (data-source-specific-SQL-statement(s))
BY
<data-source-name> <alias>
Syntax Description
Data-source-specific-SQL-statements
specifies a dynamic non-query, data source-specific SQL statement. Depending on
your data source, the SQL statement can be case sensitive. The statement is passed to
the data source exactly as you type it.
CREATE
creates a data source table, view, index, or other data source object, depending on
how the statement is specified.
DELETE
deletes rows from a data source table.
DROP
drops a data source table, view, or other data source object, depending on how
the statement is specified.
GRANT
gives users the authority to access or modify objects such as tables or views.
INSERT
inserts rows to a data source table.
REVOKE
revokes the access or modification privileges that were given to users by the
GRANT statement.
UPDATE
updates the data in the specified columns of a row in a data source table.
Requirements:
At least one statement is required.
The statement must be enclosed in parentheses.
Data-source-name
specifies the data-source-name to which you direct the data source-specific SQL
statements. The EXECUTE statement's data-source-name must match the data-
source-name specified in the CONNECT statement.
Alias
specifies the data source alias that was defined in the CONNECT statement. The
EXECUTE statement's alias must match the alias that you specified in the
CONNECT statement.
Details
The EXECUTE statement sends dynamic non-query, data source-specificSQL
statements to the data source and processes those statements. The EXECUTE statement
cannot be stored as part of a pass-through facility query in an SQL view.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the
SAS log using the macros. The contents are reset after each pass-through facility
statement is executed.
CONNECTION TO Component 139
CONNECTION TO Component
Retrieves and uses data source data in a PROC SQL query or view.
Valid in: SQL procedure STEP statements.
Syntax
CONNECT TO a data- source AS alias (connect statement arguments)
(database connection-options)
ALIAS
DATABASE CONNECTION ARGUMENTS
DATA SOURCE NAME
CONNECTION COMPONENT
Optional Arguments
ALIAS
specifies the data source alias for the connection. If you specify an alias, the keyword
AS must appear before the alias.
Restriction: ALIAS is not supported if the CONNECT statement is omitted.
Requirement: The range of the ALIAS is between 1 and 32 characters.
Note: The data source name is used as the name of the pass-through connection if an
alias is not specified.
CONNECTION COMPONENT
specifies arguments that indicate whether you can make multiple connections, shared
connections, or unique connections, to the database.
DATA SOURCE NAME
specifies the data source name to which you want to connect and direct the data
source-specific SQL statements.
Requirement: You must use back quotation marks ( ` ), not single (forward)
quotation marks, to enclose any data source name that contains a space.
140 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
Note: The data source name becomes the name of the pass-through connection if an
alias is not specified.
DATABASE CONNECTION ARGUMENTS
specifies the data source-specific arguments to the pass-through facility that are
needed by the SQL procedure to connect to a data source.
NO prompting is not available. You must specify the data source as a physical
filename or complete path.
REQUIRED connect with a valid data-source-name. If a valid connection is not
specified, you are prompted for the connection options. The prompt enables you to
change the data source file and other properties.
NOPROMPT disables the display of the Data Link Properties window. Prompting is
not available.
PROMPT enables the display of the Data Link Properties window. Prompting is
available.
UDL= enables you to browse and select an existing Microsoft data link file (.udl).
Note: This statement option applies to the INIT= argument and the UDL= argument.
UDL= "path and filename"
specifies the path and filename for a UDL (a Microsoft data link file ). This option
does not support SAS filerefs. The macro variable SYSDBMSG is set upon
successful completion.
UDL_FILE='C:\WinNT\profiles\me\desktop\MyDBLink.udl';
%PUT %SUPERQ(SYSDBMSG);
Alias: UDL_FILE
CONNECTION TO Component 141
PASSWORD= user-password
specifies a password required by the data source for the user account.
Alias: PWD | PW | PASS | PASSWORD
Note: Passwords are case sensitive.
USER= user-id
specifies a user account name, if one is required to connect to the data source. For
Microsoft Access, if you have user-level security set on your .mdb file, you need to
use the USER= and PASSWORD= options to access your file.
Alias: UID
Restriction: Microsoft Access database files only.
Note: Use the SERVERUSER= option to connect to a server.
Details
The CONNECTION component specifies the data source connection to use or to create.
CONNECTION enables you to retrieve data source data directly through an SQL
procedure query.
• The CONNECTION component can be used in any FROM clause, including those in
nested queries (subqueries).
• You can store a pass-through facility query in an SQL view and then use that view in
SAS programs.
• When you create an SQL view, any options that you specify in the corresponding
CONNECTION statement are stored too. Thus, when the SQL view is used in a SAS
program, SAS can establish the appropriate connection to the data source.
• Because external data sources and SAS have different naming conventions, some
data source column names might be changed when you retrieve data source data
through the CONNECTION component.
Details
You can use these data types when you use the CREATE statement using the SQL pass-
through facility to create a table. You can also use the data types when you use data set
option DBTYPE to change the data type for a loaded column.
Data Type Column Size Create Parameters Prefix and Suffix Comments
BIT 2
BYTE 3
SHORT 5
LONG 10
SINGLE 7
DOUBLE 15
DECIMAL 28 precision,scale *
COUNTER 10 **
GUID 16
CURRENCY 19
DATETIME 8 # ***
LONGTEXT 536,870,910 ††
VARBINARY 255
BIGBINARY 4000
Microsoft Jet and Microsoft Ace Provider Supported Data Types 143
Data Type Column Size Create Parameters Prefix and Suffix Comments
LONGBINARY 1,073,741,823 ††
* When you use the data type DECIMAL, you can specify precision and scale.
** When you use the DBTYPE option, theCOUNTER data type is valid only when you set INSERT SQL=YES. The COUNTER data
type is supported only in the pass-through facility when you create a table.
*** When you use the pass-through facility to set a date/time value, you must add the prefix and suffix, #. For example, #01/01/2001# and
#03/12/1999 12:12:12#.
† When you use the data types VARCHAR or VARBINARY, you must specify the maximum length.
†† All Excel columns can have a null value. Do not specify NOTNULL for a column when you create an Excel table. You can
specifyNULL or NULL attributes for a field when you create a Microsoft Excel table.
Examples
Syntax
ACE | JET : schema-rowset'parameter-1, ..., parameter-n
Required Arguments
SAS/ACCESS Interface to PC Files supports a number of special queries that return
information such as available tables, columns, and procedures.
ACE | JET :
required to distinguish special queries from regular queries.
schema-rowset
the specific schema rowset that is being called. The valid schema rowsets are listed
below.
"parameter-1, ..., parameter-n"
• Separate parameters from one another by commas.
• All parameters are optional.
• Quotation marks are required.
• If you specify some, but not all, parameters within an argument, use commas to
indicate the omitted parameters.
Details
ACE|JET::CHECK_CONSTRAINTS
returns the check constraints that are defined in the database file.
ACE|JET::COLUMNS<"table-name"> , <"column-name">
returns the columns of the tables that are defined in the database file.
ACE|JET::CONSTRAINT_COLUMN_USAGE<"table-name"> ,<"column-name">
returns the columns that are used by referential constraints, unique constraints,
check constraints, and assertions that are defined in the database file.
ACE|JET::FOREIGN_KEYS<"primary-key-table-name"> , <"foreign-key-table-name">
returns the foreign key columns that are defined in the database file.
ACE|JET::INDEXES<"index-name"> , <"table-name">
returns the indexes that are defined in the database file.
ACE|JET::KEY_COLUMN_USAGE<"constraint-name"> , <"table-name"> ,
<"column-name">
returns the key columns that are defined in the database file.
ACE|JET::PRIMARY_KEYS<"table-name">
returns the primary key columns that are defined in the database file.
ACE|JET::PROCEDURES <"procedure-name">
returns the procedures that are defined in the database file.
Special Jet Commands 145
ACE|JET::PROVIDER_TYPES
returns information about the base data types that are supported by the Jet data provider.
ACE|JET::REFERENTIAL_CONSTRAINTS<"constraint-name">
returns the referential constraints that are defined in the database file.
ACE|JET:: STATISTICS <"table-name">
returns the statistics that are defined in the database file.
ACE|JET::TABLE_CONSTRAINTS <"constraint-name"> , <"table-name"> ,
<"constraint-type">
returns the table constraints that are defined in the database file.
ACE|JET::TABLES <"table-name"> , <"table-type">
returns the tables that are defined in the database file.
ACE|JET::VIEWS <"table-name">
returns the viewed tables that are defined in the database file.
Examples
Possible Values
JET::COMMAND general format
JET:: required to distinguish special queries from regular
queries.
JET::COMMIT to commit a transaction
146 Chapter 12 • Pass-Through Facility for Access and Excel on Microsoft Windows
PROC SQL;
CONNECT TO access( PATH='d:\dbms\access\test.mdb' AUTOCOMMIT= no );
EXECUTE(CREATE table x (c1 int) ) BY access;
EXECUTE(INSERT INTO x values( 1 ) ) BY access;
Chapter 13
File-Specific Reference for
Access and Excel on Microsoft
Windows
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.
CAUTION:
Due to the use of the Microsoft Jet Excel engine and the Microsoft Ace Excel
engine, the SAS engines for Excel have limited update and delete capability.
There might be other unsolved issues. You should therefore avoid using the
update and delete features. Back up your Excel files before you try using any
update functions.
CAUTION:
Although you can connect to an Excel file while the application is opening it,
any updates to the Excel file can cause the SAS Excel engine to malfunction. It
is recommended that you close the application that is using the Excel file,
disconnect, and then reconnect the file in SAS. Set the LIBNAME option,
FILELOCK=YES, to ensure that Excel or other applications have not opened the
connected Excel file.
148 Chapter 13 • File-Specific Reference for Access and Excel on Microsoft Windows
Connection Options
You can use this connection option in the LIBNAME statement or in the PROC SQL
CONNECT statement to connect to a Microsoft Excel file.
HEADER= YES | NO
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.
MIXED= YES | NO
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.
YES
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.
CAUTION:
Due to a limitation in the Microsoft Ace and Microsoft Jet engines,
MIXED=YES could result in improper text variable lengths.
NO
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
Restrictions:
DBMS= only
This option is available only for Windows reading Excel data into SAS. You
cannot use this option for delimited files.
Registry settings might affect the behavior of the MIXED= option. Refer to the
following tables for Registry Key location and Registry Settings for the MIXED=
option for additional information.
Microsoft Excel Workbook Files 149
Table 13.1 Registry Key for TypeGuessRow Based on Office Version or Engine
Office Version or
Environment Engine Registry Key
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.
CAUTION
Changing the TypeGuessRows value cause a scan to fail if you set it
the value higher than 16384. Changes also affect any software that
uses the Microsoft Jet provider to access Excel file data, including
accessing Excel data in a Microsoft Access database. The
TypeGuessRows value is registered with and controlled by Microsoft.
It is therefore recommended that you set the value to 0
150 Chapter 13 • File-Specific Reference for Access and Excel on Microsoft Windows
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.
CAUTION:
These settings are registered by the Microsoft Jet engine. Changing
settings such as TypeGuessRows for Microsoft Jet engine in the Windows
registry affects all software that uses Microsoft Jet engine to import data.
This includes Microsoft Office products, as well as other database products
and application software.
General Numeric
Number Numeric
Scientific Numeric
* 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.
** 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.
*** 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” on page 114 during output processing.
Table 13.4 Default Excel Formats Assigned for SAS Variable Formats
$BINARYw. Text
$CHARw. Text
$HEX w. Text
$w. Text
w.d Number
BESTw. Number
152 Chapter 13 • File-Specific Reference for Access and Excel on Microsoft Windows
BINARYw. 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
Microsoft Access Files 153
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;
Statements
The SAS/ACCESS LIBNAME statement connects to a Microsoft Access database MDB
file in READ/WRITE mode by default. The SAS CONNECT statement in PROC SQL
also connects in READ/WRITE mode by default. Set the LIBNAME option
ACCESS=READONLY to connect to the file in READONLY mode.
The SAS engine for the Microsoft Access database uses the Microsoft Jet Provider to
connect to Microsoft Access data in the MDB file. A connection requires an existing
MDB file. The engine knows the version of the MDB file that the Microsoft Access
database saves.
The engine supports some special queries. The queries return information such as
available tables, primary keys, foreign keys, and indexes. For more information, see
“Pass-Through Facility on Microsoft Windows” on page 129.
Connection Options
Ô)ýŸÉDM-ÔQôœ°‚@ÝL˚çÌ£ÒÃŒôA@xÒ•Í”tüŽ}ر¡¶÷•¦Må hóej¿ß\<(žF,¤ø˘+ÉÄ
ÒE+fi‘FØ·Çx˜�ô’]¶ob¤Å–ïNšˇ3öˇfiMC3Ñ·Éï½å¿éAïš*¾#…×§Hˇƒ Ö−ORY{ãH ðý΄©ôq7Eµ;šüåÎpño«#3ı‚ü!ø-u
statement.
Note: You can use USER, PASSWORD, DBPASSWORD, and DBSYSFILE to access
your .mdb files, but it does not change your current security settings for those files.
154 Chapter 13 • File-Specific Reference for Access and Excel on Microsoft Windows
DBPASSWORD= 'database-file-password'
enables you to access your file if you have database-level security set in your .mdb
file. A database password is case sensitive and can be defined in addition to user-
level security. Do not include ampersands, quotation marks, or invisible characters in
your password.
Alias: DBPWD | DBPW
DBSYSFILE='workgroup-information-file’
contains information about the users in a workgroup based on information that
defines your Microsoft Access database. Any user and group accounts or passwords
that you create are saved in the workgroup information file.
Alias: DBSYS | WGDB
PASSWORD= ‘user-password’
specifies a password for the user account. A password can be 1 to 14 characters long
and can include any characters except ASCII character 0 (null). Passwords are case
sensitive. Do not include ampersands, quotation marks, or invisible characters in
your password.
Alias: PWD | PW
Note: If you have user-level security set in your .mdb file, you need to use this
option and the USER option to be able to access your file.
USER= 'user-ID'
specifies a user account name. User names can be 1 to 20 characters long and can
include alphabetic characters, accented characters, numbers, and spaces.
Alias: UID | USERID
Note: If you have user-level security set in your .mdb file, you need to use this
option and the PASSWORD option to be able to access your file.
Table 13.5 Default SAS Formats Assigned for MDB Data Types
MDB Field Data Type SAS Variable Format SAS Variable Type
Yes|No 2. Numeric
Number 4. Numeric
(FieldSize=Byte)
Number 6. Numeric
(FieldSize=Integer)
MDB Field Data Type SAS Variable Format SAS Variable Type
Number Numeric
(FieldSize=Single)
Number Numeric
(FieldSize=Double)
* The default format is DATETIME. You can use USEDATE=YES to change format from DATETIME. to
DATE. You can also use the SASDATEFMT option to change the format to other date or date and time
formats.
** The SAS date/time value uses 01Jan1960 as the cutoff date. The Jet provider date/ time value uses
30Dec1899 as the cutoff date.
*** The width of $w. is equal to the field size of the column defined in your Microsoft Access table.
† When SCANMEMO=YES (default is NO), the width value of $w. is determined by the longest string of
data that is scanned in the field. It can also be determined by the value specified in the DBMAX_TEXT=
option, whichever is less. Otherwise, when the option SCAN_TEXT=NO, the width value of $w. is equal
to the value specified in DBMAX_TEXT= option.
†† The w width value is equal to the precision value plus 1. The d decimal value is equal to the scale value,
where precision and scale are defined for the column in the table.
The following table shows the default .mdb data types that SAS/ACCESS assigns to
SAS variable formats. These data types are assigned when you write SAS data to
an .mdb file using the LIBNAME engine. You can override these default conversions by
using the DBTYPE data set option during processing.
Table 13.6 Default DB Data Types Assigned for SAS Variable Formats
w.d Number **
BESTw. Number **
BINARYw. Number **
COMMAXw.d Number **
Ew. Number **
FRACTw. Number **
HEXw. Number **
NEGPARENw.d Number **
PERCENTw.d Number **
DOLLARw.d Currency
DOLLARXw.d Currency
DATEw. Date/Time
DATETIMEw.d Date/Time
DDMMYYw. Date/Time
HHMMw.d Date/Time
JULDAYw. Date/Time
JULIANw. Date/Time
MMDDYYw. Date/Time
MMYYw.d Date/Time
MONTHw. Date/Time
MOYYw. Date/Time
WEEKDATEw. Date/Time
WEEKDATXw. Date/Time
WEEKDAYw. Date/Time
Microsoft Access Files 157
WORDDATEw. Date/Time
WORDDATXw. Date/Time
* If the character format length is greater than 255 characters, the loaded format is Memo. Otherwise, the
loaded format is Text.
** For Microsoft Access 2000, 2002, and 2003, a SAS numeric data type with no format specified is
converted to a number data type with a double field size. If the format is specified as w. in SAS, the
loaded data type is a number with a long integer field size. If the format is specified as w.d in SAS, the
loaded data type is a number data type with a decimal field size. For Microsoft Access 97, if the format is
specified as w. in SAS, the loaded data type is a number with a long integer field size. Otherwise, the SAS
numeric data type is converted to a number data type with a double field size. However, you can set the
SAS environment variable, LOAD_DBL=YES, to force a SAS numeric data type to be loaded into a
numeric data type with a Double field size.
Example:
DATA test;
FORMAT j 5. k 6.2;
i=123.45; j=12345; k=123.45;
RUN;
When importing data with the SCANTIME=YES option, SAS scans date/time values in
the columns and assigns the TIME. format if all the values are in the year 1960.
Otherwise SAS assigns the DATETIME. format to the columns.
/* Reset to default value */
OPTIONS SET=TIME_VAL ONEDAY;
By default, SAS loads the numeric value of format w.d with a decimal field size into
Access database files, Version 2000 or later. The decimal type field takes more space
than a double type field. To manage your storage space, set the environment variable
with the following statement:
/* To have SAS numeric values loaded into an Access database
with a double field type, to save storage space. */
OPTIONS SET=LOAD_DBL YES;
Part 4
Chapter 14
PC Files Server Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Chapter 15
LIBNAME Statement for PCFILES Engine on Linux, UNIX, and
Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Chapter 16
Pass-Through Facility: PCFILES on Linux, UNIX, and Microsoft
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Chapter 17
Special Query Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
160
161
Chapter 14
PC Files Server Administration
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
PC Files Server Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
PC Files Server Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
PC Files Server Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Windows Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Service Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Desktop Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Desktop Application Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Window Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
PC Files Server Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Configuring the PC Files Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Port Number or Service Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Maximum Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Data Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Authentication (Security Enforcement) Overview . . . . . . . . . . . . . . . . . . . . . . . . . 167
Access to PC Files Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Access to Individual Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
System Administrator Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Security Model for Microsoft Windows Vista and Above . . . . . . . . . . . . . . . . . . . 168
PC Files Server Autostart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Local Security Policy Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
User Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Configure User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Shared Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
162 Chapter 14 • PC Files Server Administration
Overview
Windows Service
The server can be manually set to run as a Windows service. To run as a Windows
service: select Start ð Control Panel ð Administrative Tools ð Services. Locate
SAS PC Files Server in the Name column. Select Properties.
Service Options
Service name: Displays the name of the service (Default). SAS PC Files Server
Display name: Specifies the name of the service. The name appears in the Name
column in the details pane.
Description: Description (Default): Enables SAS/ACCESS Interface to PC files, such as
Excel and Microsoft Access.
Path to executable: specifies the path and filename of the service.
'C:\Program Files\SAS\PCFilesServer\9.3\pcfservice.exe' -name
"SAS PC Files Server"
Desktop Application
Overview
To run server mode, stop the service mode. Start ð Control Panel ð Administrative
Tools ð Services.
Locate, and then open the Properties window for SAS PC Files Server. Click Stop to
stop the service.
Desktop Application 165
Window Items
• Server Name: Names the Windows PC where PC Files Server is running.
• Service | Port: A communications end point at which a server listens for a request
for service from the client application. The default port is 9621.
166 Chapter 14 • PC Files Server Administration
• Max Connections: The maximum number of concurrent connections that this server
supports.
• Data Encryption: Encrypts data during transfer.
• Authentication Required: Requires users to provide credentials before connecting
to PC Files Server. These can be in the form of a user ID and password or integrated
windows authentication (SSPI).
• Allow Integrated Windows Authentication (SSPI) : Windows 64–bit users can
process credentials between Windows PCs without having to explicitly give a user
ID and password.
Note: This option is available only when Authentication Required is selected.
• Change Options: Displays a dialog box that enables you to change the connection
options. A note states that the PC Files Server must be restarted in order for the
changes to take effect.
• Restart Server: Restarts the server including all setting changes.
• Shutdown Server: Stops the server and closes the application window.
• Host Name: Lists host names of active server connections.
• DSN | File Access: Displays file access requests of active server connections.
• User ID: Displays the user ID of active server connections.
• Current Client Connections: Displays the total number of active connections.
Note: When a single user opens multiple connections, this displays the most current
information.
• Peak Client Connections: The greatest number of active connections during the
current server session.
TIP To find out if the 32-bit or 64-bit version of the PC Files Server is installed, use
Help ð About from the application menu.
Maximum Connections
Max Connections specifies the number of concurrent connections that the server can
support. Configure the number of connections based on the load that you expect from
your SAS clients.
Each command that uses the server uses one connection. There can be multiple users
from different SAS sessions accessing the server concurrently. Consider all the
connections when setting the Max Connections value. The number of Max
Connections is saved in the Windows registry, and it is used each time the PC Files
Server is run.
Data Encryption
To enable data encryption between SAS/ACCESS Interface to PC Files on the client and
PC Files Server, select the Data Encryption check box.
The state of the Data Encryption is saved in the Windows registry, and it is used each
time PC Files Server is run.
Authentication
Note: If the client PC is on a domain, the credentials are compared to the domain data,
instead of the local data.
Windows service or if the Windows security features have been disabled for Windows
Vista and above.
User Authentication
For server user authentication to work, the server must be able to create user–specific
subprocesses with the credentials specified. Windows allows this only if certain
Windows Security settings are set on the PC running the server.
170 Chapter 14 • PC Files Server Administration
When running the server exclusively as a Windows service, use the default account of
SYSTEM. Changes might not be needed if the SYSTEM account has all the required
privileges set.
Constraints
• You cannot mix 32- and 64-bit ACE ODBC drivers on the same machine (64-bit
ACE available starting with Microsoft Office 2010).
• You cannot mix 32- and 64-bit PC Files Servers on the same machine.
• The “bitness” of the ACE driver must match the “bitness” of PC Files Server. The
installer enforces this but care should be taken if the ACE driver is ever replaced.
Shared Information 171
• If SAS on Windows matches the “bitness” of the installed ACE driver, then PC files
can be accessed directly using the EXCEL and ACCESS engines.
• If SAS on Windows does not match the “bitness” of the installed ACE driver, then
PC Files Server must be used to bridge the “bitness” gap. The Autostart feature
simplifies this when running SAS on Windows.
• The server can run in server mode or service mode. However, only one instance of
the server can be running on a single PC at any given time.
• Service names and port numbers must be unique on a given PC.
• To modify the settings to follow the constraints:
1. Stop the server.
2. Make necessary changes.
3. Restart the server.
• Each time that you stop or restart the server, all users' sessions are closed. Closing
these sessions might result in loss of data.
• Although you can change server configuration only in server mode, the updated
values also apply when running in service mode.
Shared Information
After the server is started and running, the clients need the following information to
access the server:
• If the clients are accessing a server that requires authentication, specify the
SERVERUSER= and SERVERPASS= options. For the Windows environment, you
can also specify the SSPI= option.
• Server name (host name or IP address of the PC running the server).
• Port number or service name. If you do not use the default value, you must specify
the port number in the LIBNAME statement on the client PC.
PORT=value;
• Path to any files, or ODBC data sources to which they have access that is relative to
the files system on the server PC, such as “C:\Excel files\mysheet.xls”. Enclose the
path in double quotation marks.
172 Chapter 14 • PC Files Server Administration
173
Chapter 15
LIBNAME Statement for PCFILES
Engine on Linux, UNIX, and
Microsoft Windows
Overview
For PC files, the SAS/ACCESS LIBNAME statement extends the SAS global
LIBNAME statement to support assigning a libref to Microsoft Excel, Microsoft Access,
and ODBC data sources. This enables you to reference spreadsheets, databases, and
ODBC sources directly in a DATA step or SAS procedure. You can also read from and
write to a Microsoft Access, Microsoft Excel, or ODBC table directly.
Dictionary
Syntax
Form 1: LIBNAME libref PCFILES LIBNAME optionsconnection-options
Form 2: LIBNAME libref CLEAR | _ALL_ CLEAR
Form 3: LIBNAME libref LIST| _ALL_ LIST;
Optional Arguments
_ALL_
specifies that CLEAR= and LIST= arguments apply the argument to all librefs.
CLEAR
clears one or all librefs.
Specify libref to clear single libref. Specify _ALL_ to clear all librefs.
connection-options
provides connection information to SAS/ACCESS to connect to your PC files. If the
connection options contain characters that are not allowed in SAS names, enclose the
values of the arguments in quotation marks. In some instances, if you specify the
appropriate system options or environment variables for your data source, you can
omit the connection options.
LIBNAME options
defines how SAS processes data source objects. For example, some LIBNAME
options can improve performance. For many tasks, you do not need to specify any of
these advanced options.
See: “LIBNAME Options” on page 121
libref
is any SAS name that serves as an alias to associate SAS with a spreadsheet, data
source, or database. A SAS libref is an alias for a virtual or physical directory. Like
the global SAS LIBNAME statement, a SAS/ACCESS libref is an alias for a
spreadsheet, database, or data source where your data is stored.
LIST
lists the attributes of one or all SAS/ACCESS libraries or SAS libraries to the SAS
log.
Specify the libref argument to list the attributes of a single library. Specify _ALL_ to
list the attributes of all the librefs in your current session.
PCFILES
is the SAS/ACCESS engine for the interface to PC files on Linux, UNIX, and
Microsoft Windows.
Details
DBSYSFILE= workgroup-information-file
specifies the workgroup information file. This file contains a collection of
information defined for the Microsoft Access database. User, group accounts, and
passwords that you create, are saved in the workgroup information file.
Alias: SYSTEMDB
Restriction: Microsoft Access database files only.
DSN= data-source-name
specifies the name of the ODBC data source that is used to access PC data through
an ODBC driver on the PC.
Restriction: This ODBC data source must be defined on the PC where the PC Files
Server is running.
MSENGINE= ACE | JET
determines the database engine to use for accessing Microsoft Excel files or
Microsoft Access databases. The Microsoft Jet engine supports Microsoft formats up
to 2003. The Microsoft Ace engine supports 2007 formats and formats in subsequent
releases of Windows.
Default: ACE
PASSWORD= user-password
specifies a password required by the data source for the user account.
Alias: PWD | PW | PASS | PASSWORD
Note: Passwords are case sensitive.
PATH= pathname
specifies the full path and filename for your Microsoft Access database or Microsoft
Excel file.
This example assigns the libref db to a Microsoft Excel file.LIBNAME db
PCFILES SERVER=D2323 PATH='c:\demo.xls';
Note: Always use the .mdb or .accdb file extension for Microsoft Access files and
the .xls, .xlsx, or .xlsb extension for Microsoft Excel files.
PORT= port-number
specifies the port number or service name that PC Files Server is listening to on the
PC.
Alias: SERVICE|SERVICE_NAME
Default: 9621
SERVER= pc-server-host-name
specifies the name of the PC running PC Files Server. This name is required for
Linux and UNIX users to connect to the server.
Restriction: Omitting the SERVER= option on Windows clients invokes Autostart.
Note: The name can be a simple computer name (wxp320), a fully qualified
network name (wxp320.domain.com), or an IP address.
SERVERPASS= server-user-password
specifies the password for the PC Files Server for the User ID given. If the account
has no password, omit this option. Always enclose the value in quotes in order to
preserve the case of the password.
Alias: SERVERPASSWORD | SERVERPW | SERVERPWD
Notes:
Syntax for PCFILES Engine on Linux, UNIX, and Microsoft Windows 177
SERVERUSER= 'domain\server-user-name'
specifies the domain name and User ID for the PC running PC Files Server. Always
enclose the value in quotes, otherwise the backslash can be misinterpreted by the
SAS parser.
Alias: SERVERUID
Notes:
If you are not on a domain, omit the domain name and the backslash.
Use the USER= option for database User IDs.
Example: LIBNAME using explicit user name and password.
LIBNAME db PCFILES PATH='C:\myfile.mdb'
SERVER=fileserv;
SERVERUSER='mydomain\myusername';
SERVERPASS='mypassword';
SSPI= YES | NO
enables the PC Files Server to allow Integrated Windows Authentication. This is a
mechanism for the Windows client and server to exchange credentials.
Default: NO
Restriction: Microsoft Windows only.
Note: SSPI can also be enabled by specifying the –SSPI option on the SAS
command line.
Example: LIBNAME using SSPI.
LIBNAME db PCFILES PATH='C:\myfile.mdb'
SERVER=localhost;
SSPI='yes';
RUN;
Notes:
Excel 2010, 2007, 2003, 2000, and 97 share the same file format. Excel 5 and 95
share a different file format.
You do not need to specify this option for an existing Excel file.
Examples
The demo.mdb database contains a number of objects, including several tables, such as
Staff. After you assign a libref, you can reference the Microsoft Access table like a SAS
data set. You can use it as a data source in any DATA step or SAS procedure. In this
PROC SQL statement, MYMDB.STAFF is the two-level SAS name for the Staff table in
the Microsoft Access database Demo.
PROC SQL;
SELECT idnum, lname
FROM mymdb.staff
WHERE state='NY'
ORDER BY lname;
QUIT;
SAS procedures such as PROC SQL, PROC PRINT, PROC CONTENTS, and PROC
DATASETS , use the libref.
List all database objects in the library with the DATASETS procedure:
PROC DATASETS LIBRARY=mymdb;
QUIT;
To improve performance, it is recommended that you use the data set options
INSERTBUFF= for writing and READBUFF= for reading and set an appropriate value.
Create a table named Invoice in a Microsoft Access database from a SAS data set
named Invoice:
PROC SQL;
CREATE TABLE mymdb.Invoice (INSERTBUFF=25) as SELECT * FROM invoice;
QUIT;
The demo.xls workbook contains a number of sheets, such as sheet1. After you assign
the libref, you can reference the Excel spreadsheet like a SAS data set and use it as a
data source in any DATA step or SAS procedure. In this example, a SAS data set is
created from a Microsoft Excel sheet:
DATA a;
SET myxls.'sheet1$'n;
RUN;
When using a LIBNAME statement with Excel, refer to Excel sheets as n-literals
because of the “$” character. If you are referencing a named range in a Microsoft Excel
spreadsheet, it is not necessary to refer to it as an n-literal.
Create a Microsoft Excel file and use a SAS data set to populate a sheet in that file.
Create a named range for the sheet:
DATA myxls.air;
SET sashelp.air;
RUN;
Use the libref with any SAS procedures such as PROC SQL, PROC PRINT, PROC
CONTENTS, and PROC DATASETS.
This SAS program uses the DATASETS procedure to list all database objects in the
library.
PROC DATASETS LIBRARY=mymdb;
QUIT;
To improve performance, it is recommended that you use the data set option
READBUFF= and set an appropriate value. This example reads in data from a range
called Invoice in a Microsoft Excel workbook.
180 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
When writing to a Microsoft Excel file, the PC Files Server does not support the
INSERTBUFF= option with value greater than 1.
PROC SQL;
SELECT * FROM myxls.Invoice (READBUFF=25);
QUIT;
Create a libref, mysqlsrv, to a SQL Server database via ODBC, using the server on
the PC:
LIBNAME mysqlsrv PCFILES SERVER=D2323 DSN=MQIS USER=scott
PWD=tiger SCHEMA=dbo;
Using the mysqlsrv libref, create a SAS data set called sqltest from the crime table
in the SQL Server database:
DATA work.sqltest;
SET mysqlsrv.crime;
RUN;
or
PROC sql;
CREATE TABLE work.sqltest AS SELECT * FROM mysqlsrv.crime;
QUIT;
Using the mysqlsrv libref, create a SQL Server table called newtable from the SAS
data set, sqltest:
DATA mysqlsrv.newtable;
SET sqltest;
RUN;
Create a libref, ora, to an Oracle database table via ODBC, using the PC Files
Server on the PC:
LIBNAME ora PCFILES SERVER=D2323 DSN=ORA9MS
USER=scott PRESERVE_TAB_NAMES=yes;
Using the ora libref, an Oracle table, oratab, is created from a SAS data set
sashelp.class:
DATA ora.oratab;
SET sashelp.class;
RUN;
Using the ora libref, a SAS data set, sastab, is created from the Oracle table emp:
DATA sastab;
SET ora.emp;
RUN;
SAS LIBNAME Options for PCFILES on Linux, UNIX, and Microsoft Windows 181
Details
Many of these LIBNAME options are also available as data set options. See “Overview
of Data Set Options” on page 103 for additional information.
Note: Note that these are advanced options that do not need to be specified for many of
the tasks that you perform.
ACCESS= READONLY
indicates that tables and views can be read but not updated.
AUTOCOMMIT= YES | NO
determines whether the ACCESS engine commits (saves) updates as soon as they are
submitted.
YES
specifies that updates are committed to a table as soon as they are submitted, and
no rollback is possible.
NO
specifies that the SAS/ACCESS engine automatically performs the commit when
it reaches the end of the file.
Default: NO
COMMAND_TIMEOUT= number-of-seconds
specifies the number of seconds that pass before a data source command times out.
Alias: TIMEOUT
Default: 0 (no time-out)
GLOBALREAD
specifies that all READ operations that access data source tables in multiple
librefs share a single connection if these conditions are met:
• the participating librefs are created by LIBNAME statements that specify
identical values for the CONNECTION= option and
CONNECTION_GROUP= option.
• the participating librefs are created by LIBNAME statements that specify
identical values for any data source connection options.
A separate connection is established for each table that is opened for update or
output operations.
GLOBALREAD is the default value for CONNECTION= option when you
specify CONNECTION_GROUP= option.
Default: SHAREDREAD
CONNECTION_GROUP= connection-group
causes operations against multiple librefs to share a connection to the data source.
Also causes operations against multiple pass-through facility CONNECT statements
to share a connection to the data source.
CURSOR_TYPE=DYNAMIC | FORWARD_ONLY | KEYSET_DRIVEN |
STATIC
specifies the cursor type for read-only cursors and for cursors to be updated.
DYNAMIC
specifies that the cursor reflects all changes that are made to the rows in a result
set as you move the cursor. The data values and the membership of rows in the
cursor can change dynamically on each fetch. This is the default for the DB2
UNIX, PC Files, and SQL server interfaces.
FORWARD_ONLY
specifies that the cursor behaves like a DYNAMIC cursor, except that it supports
only fetching of rows sequentially.
KEYSET_DRIVEN
specifies that the cursor determines which rows belong to the result set when you
open the cursor. Changes that are made to these rows are reflected as you scroll
around the cursor.
STATIC
specifies that the complete result set is built when you open the cursor. No
changes that are made to the rows in the result set after the cursor is opened are
reflected in the cursor. Static cursors are read only.
Alias: CURSOR
DBCOMMIT= number-of-rows
affects update, delete, and insert processing. The number of rows that are processed
includes rows that are not processed successfully. If you set DBCOMMIT=0, a
commit is issued only once (after the procedure or DATA step completes). If the
DBCOMMIT= option is explicitly set, SAS/ACCESS fails any update that has a
WHERE clause.
Note: If you specify both DBCOMMIT= and ERRLIMIT=, the DBCOMMIT= is
issued before the rollback. Because the DBCOMMIT= option is issued before the
rollback, the DBCOMMIT= option overrides the ERRLIMIT= option (rollback)
in this situation.
SAS LIBNAME Options for PCFILES on Linux, UNIX, and Microsoft Windows 183
Default: 1,000 (inserting) or 0 (updating; commit occurs when data set or procedure
completes)
DBGEN_NAME= DBMS | SAS
specifies that the data source columns are renamed and the format that the names
follow.
DBMS
specifies that the data source columns are renamed to valid SAS variable names.
Disallowed characters are converted to underscores. If a column is converted to a
name that already exists, then a sequence number is appended to the end of the
new name.
SAS
specifies that data source columns are renamed to the format _COL n, where n is
the column number (starting with zero).
Default: DBMS
DBMAX_TEXT= n
specifies an integer between 1 and 32,767 that indicates the maximum length for a
character string. Longer character strings are truncated. This option applies only
when you are reading, appending, and updating character data in a Microsoft Access
database or Excel workbook from SAS. Although you can specify a value less than
256, it is not recommended for reading data from a Microsoft Access database.
Default: 1,024
DBNULLKEYS= YES | NO
specifies column definitions.
YES
If there might be NULL values in the transaction table or the master table for the
columns that you specify in the DBKEY= option, use DBNULLKEYS=YES.
If you specify DBNULLKEYS=YES and a column that is not defined as NOT
NULL in the DBKEY= option, SAS generates a WHERE clause that finds
NULL values.
If you specify DBKEY=COLUMN and COLUMN is not defined as NOT NULL,
SAS generates a WHERE clause that enables SAS to prepare the statement once.
The statement can be used any value in the column. For example WHERE
((COLUMN =?) OR ((COLUMN IS NULL) AND (? IS NULL)));.
Note: This syntax has the potential to be much less efficient than the shorter
form of the WHERE clause.
NO
When you specify DBNULLKEYS=NO or specify a column as NOT NULL in
the DBKEY= option, SAS generates a simple WHERE clause. If you know that
there are no NULL values for the columns that you specify in the DBKEY=
option, you can use DBNULLKEYS=NO.
If you specify DBNULLKEYS=NO and DBKEY=COLUMN, SAS generates a
shorter form of the WHERE clause. This is true whether DBKEY=COLUMN is
defined as NOT NULL or not.
Default: YES
DEFER= NO | YES
enables you to specify when the connection to the data source occurs.
NO
specifies that the connection to the data source occurs when the libref is assigned
by a LIBNAME statement.
YES
specifies that the connection to the data source occurs when a table in the data
source is opened.
Default: NO
DIRECT_SQL= YES | NO | NONE | specific-functionality
specify whether generated SQL is passed to the data source for processing.
YES
specifies that, whenever possible, generated SQL, except multiple outer joins, is
passed to the data source for processing. This includes SQL that is generated
from PROC SQL, SAS functions that can be converted into data source
functions, joins, and WHERE clauses.
NO
specifies that generated SQL from PROC SQL is not passed to the data source
for processing. This is the same as specifying the specific-functionality value
NOGENSQL.
NONE
specifies that generated SQL is not passed to the data source for processing. This
includes SQL that is generated from PROC SQL, SAS functions that can be
converted into data source functions, joins, and WHERE clauses.
specific-functionality
identifies types of processing to be handled by SAS instead of the data source.
You can specify these values:
NOFUNCTIONS
causes SAS to handle all SAS functions. The SAS functions are not
converted into data source functions and are not passed to the data source for
processing.
NOMULTOUTJOINS
causes SAS to process outer joins that involve more than two tables. This
option does not affect outer joins of two tables.
Note: This option is always turned ON for the Jet engine.
NOGENSQL
prevents PROC SQL from generating SQL to pass to the data source for
processing.
NOWHERE
prevents WHERE clauses from being passed to the data source for
processing. This includes SAS WHERE clauses and PROC SQL-generated or
PROC SQL specified WHERE clauses.
Default: YES
INSERTBUFF= number-of-rows
specifies the number of rows for a multiple-row insert. The value for
INSERTBUFF= must be a positive number. If the INSERTBUFF= value is greater
than the DBCOMMIT= value, the DBCOMMIT= value overrides it. If you assign a
value that is greater 1, the SAS application notes that indicate the success or failure
SAS LIBNAME Options for PCFILES on Linux, UNIX, and Microsoft Windows 185
READBUFF= number-of-rows
specifies the number of rows to use when you are reading data from a data source.
Setting a higher value for this option reduces I/O and increases performance, but also
increases memory usage. In addition, if too many rows are read at once, values
returned to SAS might be out of date.
Alias: ROWSET | ROWSET_SIZE
Default: 1
SCAN_TEXTSIZE= YES | NO
specifies whether to scan the length of text data for a data source column and use the
length of the longest string data found as the SAS column width.
YES
scans the length of text data for a data source column and use the length of the
longest string data found as the SAS variable width. If the maximum length
found is greater than what is specified in the DBMAX_TEXT= option, the
smaller value is applied as the SAS variable length.
For Excel, this option applies to all character data type columns. For Microsoft
Access, this applies only to the MEMO data type field. It does not apply to the
TEXT (less than 256 characters long) field.
NO
does not scan the length of text data for a data source column. The column length
returned from the Jet provider is used as the SAS variable width. If the returned
length is greater than the length specified with the DBMAX_TEXT= option, the
smaller value is assigned to the SAS variable length.
Note: Specify SCANTEXT=NO when you need to update data in the Microsoft
Access database or Excel workbook.
Alias: SCANTEXT | SCANMEMO
Default: YES for a Microsoft Excel workbook
NO for a Microsoft Access database
SCAN_TIMETYPE= YES | NO
specifies whether to scan all row values for a DATE or TIME data type field, and
automatically determine the TIME data type based on the setting. Option values YES
turn on the scan function. Option value NO turns off the scan function.
YES
specifies that a Microsoft Excel column with all time values (internal value is
less than 1) is assigned a TIME8. format.
NO
specifies that the SCAN function is not enabled.
Alias: SCAN_TIME| SCANTIME
Default: NO
See: USE_DATETYPE
SPOOL= YES | NO
specifies whether SAS creates a utility spool file during read transactions that read
data more than once.
186 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
YES
specifies that SAS creates a utility spool file into which it writes the rows that are
read the first time. For subsequent passes through the data, the rows are read
from the utility spool file rather than being reread from the data source table.
This guarantees that the row set is the same for every pass through the data.
NO
specifies that the required rows for all passes of the data are read from the data
source table. No spool file is written. There is no guarantee that the row set is the
same for each pass through the data.
Default: YES
STRINGDATES= YES | NO
specifies whether datetime values are read from the data source as character strings
or as numeric date values. STRINGDATES= is not available as a data set option.
YES
specifies that SAS/ACCESS reads datetime values as character strings.
NO
specifies that SAS/ACCESS reads datetime values as numeric date values.
Alias: STRDATES
Default: NO
USE_DATETYPE= YES | NO
specifies whether to use DATE9. format for date columns in the data source table
while importing data from a Microsoft Excel workbook. Specifies whether to use a
format for date columns in the data source table while importing data from a
Microsoft Access table
YES
specifies that the SAS DATE9. format is assigned for date columns in Excel data
source table.
NO
specifies that the SAS DATE formats are not assigned to the data source table.
Alias: USE_DATE | USEDATE
Default: YES for a Microsoft Excel workbook
NO for a Microsoft Access database
Data Set Options for PCFILES on Linux, UNIX, and Microsoft Windows
You can specify SAS/ACCESS data set options on a SAS data set when you access PC files data with the
LIBNAME Statement Syntax for PC Files on Linux and UNIX.
Note: A data set option applies only to the data set on which it is specified, and it remains
in effect for the duration of the DATA step or procedure.
See: “Overview of Data Set Options” on page 103, “Syntax for PCFILES Engine on Linux,
UNIX, and Microsoft Windows” on page 174.
Details
This generic example shows the format of data set options:
COMMAND_TIMEOUT 187
You can use the CNTLLEV=, DROP=, FIRSTOBS=, IN=, KEEP=, OBS=, RENAME=,
and WHERE= SAS data set options when you access PC files data. The REPLACE=
SAS data set option is not supported by SAS/ACCESS interfaces. For information about
using SAS data set options, refer to SAS Data Set Options: Reference.
Note: Specifying data set options in PROC SQL might reduce performance, because it
prevents operations from being passed to the data source for processing.
AUTOCOMMIT
Determines whether the ACCESS engine commits (saves) updates as soon as you submit them.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
AUTOCOMMIT=YES | NO
Syntax Description
YES
specifies that updates are committed to a table as soon as they are submitted, and no
rollback is possible.
NO
specifies that the SAS/ACCESS engine automatically performs the commit when it
reaches the end of the file.
COMMAND_TIMEOUT
Specifies the number of seconds to wait before a command times out.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
See: To assign this option to a group of tables, use the COMMAND_TIMEOUT option
specified in “LIBNAME Options” on page 121.
Syntax
COMMAND_TIMEOUT= number-of-seconds
Syntax Description
number-of-seconds
the number of seconds to wait before a command times out.
188 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
CURSOR_TYPE
Specifies the cursor type for read-only cursors and for cursors to be updated.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
Syntax
CURSOR_TYPE=KEYSET_DRIVEN | STATIC
Syntax Description
KEYSET_DRIVEN
specifies that the cursor determines which rows belong to the result set when the
cursor is opened. However, changes that are made to these rows are reflected as you
move the cursor.
STATIC
specifies that the cursor builds the complete result set when the cursor is opened. No
changes made to the rows in the result set after the cursor is opened are reflected in
the cursor. Static cursors are read-only.
Details
By default, this option is not set, and the Microsoft Jet provider uses a default. The OLE
DB properties applied to an open row set are as follows:
KEYSET_ DBPROP_OTHERINSERT=FALSE,
DRIVEN DBPROP_OTHERUPDATEDELETE=TRUE
STATIC DBPROP_OTHERINSERT=FALSE,
DBPROP_OTHERUPDATEDELETE=FALSE
See your OLE DB programmer reference documentation for details about these
properties.
See Also
To assign this option to a group of tables, use the CURSOR_TYPE option specified in
“LIBNAME Options” on page 121.
DBCOMMIT
Enables you to issue a commit statement automatically after a specified number of rows have been
processed.
DBCONDITION 189
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option default: 1000
Syntax
DBCOMMIT=number-of-rows
Syntax Description
number-of-rows
is an integer greater than or equal to 0.
Details
DBCOMMIT affects update, delete, and insert processing. The number of rows
processed includes rows that are not processed successfully. When DBCOMMIT=0, a
commit is issued only once after the procedure or DATA step completes.
If the DBCOMMIT option is explicitly set, SAS/ACCESS fails any update that has a
WHERE clause.
Note: If you specify the DBCOMMIT= option and the ERRLIMIT= option, and these
options collide during processing, then the DBCOMMIT= option is issued first and
the rollback is issued second. Because the DBCOMMIT= option is issued before the
ERRLIMIT= option, the DBCOMMIT= option overrides the ERRLIMIT= option in
this situation.
See Also
• “ERRLIMIT” on page 115
• “LIBNAME Options” on page 121
DBCONDITION
Specifies criteria for subsetting and ordering data.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBCONDITION=SQL-query-clause
190 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
Syntax Description
SQL-query-clause
is a data source-specific SQL query clause, such as WHERE, GROUP BY,
HAVING, or ORDER BY.
Details
This option enables you to specify selection criteria in the form of data source-specific
SQL query clauses, which the SAS/ACCESS engine passes directly to the data source
for processing. When selection criteria are passed directly to the data source for
processing, performance is often enhanced. The data source checks the criteria for
syntax errors when it receives the SQL query.
The option is ignored when you use DBCONDITION.
See Also
“DBKEY” on page 109
DBCREATE_TABLE_OPTS
Specifies data source-specific syntax to add to the CREATE TABLE statement.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
DBCREATE_TABLE_OPTS='SQL-clauses'
Syntax Description
SQL-clauses
are one or more data source-specific clauses that can be appended to the end of an
SQL CREATE TABLE statement.
Details
This option enables you to add data source-specific clauses to the end of the SQL
CREATE TABLE statement. The SAS/ACCESS engine passes the SQL CREATE
TABLE statement and its clauses to the data source, which executes the statement and
creates the table.
See Also
To assign this option to a group of tables, use the DBCREATE_TABLE_OPTS= option
specified in “LIBNAME Options” on page 121.
DBENCODING
Specifies the encoding character set to use in the Microsoft Access database or in the Microsoft Excel
workbook.
DBFORCE 191
Syntax
DBENCODING=12–byte SAS encoding-value
Syntax Description
The 12-byte SAS encoding-value is an encoding value that SAS defines. It can be up to
12 characters long. For a list of valid values, see the section “Encoding Values in SAS
Language Elements” in SAS National Language Support Reference Guide.
Details
Specify the encoding character set to use in your Microsoft Access database or Excel
workbook file. This option enables SAS to transcode character data between the SAS
session encoding and the DBENCODING value.
It is recommended that you use UNICODE=YES instead of DBENCODING. Setting
UNICODE=YES is equivalent to setting DBENCODING='UTF-16'.
This enables SAS to bind text in wide character format. SAS is also enabled to transcode
data between a SAS session. For example, Chinese BIG5 encoding, and Access or Excel
in UNICODE encoding. In a UTF-8 session, SAS assumes that UNICODE=YES.
Transcoding is a process that converts text data from one encoding to another encoding.
Note
• It does not translate from one language to another language.
• It does not translate the English language to the Japanese language.
• It does not translate the Chinese language to the Japanese language.
• It might map some Chinese characters to Japanese Hanzi characters.
DBFORCE
Specifies whether to force the truncation of data during insert processing.
Valid in: DATA and PROC steps
Default: NO
Syntax
DBFORCE= YES | NO
Syntax Description
YES
specifies that the rows that contain data values that exceed the length of the column
are inserted, and the data values are truncated to fit the column width.
192 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
NO
specifies that the rows that contain data values that exceed the column length are not
inserted.
Details
This option determines how the SAS/ACCESS engine handles rows that contain data
values that exceed the length of the column.
The SAS data set option FORCE= overrides this option when it is used with PROC
APPEND or the PROC SQL UPDATE statement. The PROC SQL UPDATE statement
does not provide a warning before truncating the data.
DBGEN_NAME
Specifies whether to rename columns automatically when they contain disallowed characters.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME option setting
Syntax
DBGEN_NAME=DBMS | SAS
Syntax Description
DBMS
specifies that disallowed characters are converted to underscores.
SAS
specifies that columns that contain disallowed characters are converted into valid
SAS variable names, using the format _COLn, where n is the column number
(starting with zero). If a name is converted to a name that already exists, a sequence
number is appended to the end of the new name.
Details
SAS retains column names when reading data, unless a column name contains characters
that SAS does not allow, such as $ or @. SAS allows alphanumeric characters and the
underscore (_).
This option is intended primarily for National Language Support. Notably the
conversion of kanji to English characters. The English characters converted from kanji
are often not allowed in SAS. If you specify DBGEN_NAME=SAS, a column named
DEPT$AMT is renamed to _COLn where n is the column number. If you specify
DBGEN_NAME=DBMS, a column named DEPT$AMT is renamed to DEPT_AMT.
See Also
To assign this option to a group of tables, use the DBGEN_NAME option specified in
“LIBNAME Options” on page 121.
DBLABEL 193
DBKEY
Improves performance for a join with a large source table and a small SAS data set (specifies a column to
use as an index).
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBKEY=<('column-1' ... 'column-n')>
Syntax Description
column
is the name of the column that forms the index on the data source table.
Details
When processing a join that involves a large data source table and a relatively small SAS
data set, you might be able to use DBKEY to improve performance.
CAUTION:
Improper use of this option can harm performance.
DBLABEL
Specifies whether to use SAS variable labels as data source column names during output processing.
Valid in: DATA and PROC steps
Default: NO
Syntax
DBLABEL=YES | NO
Syntax Description
YES
specifies that SAS variable labels are used as data source column names during
output processing.
NO
specifies that SAS variable names are used as data source column names.
Details
This option is valid only for creating data source tables.
194 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
Note: Only up to 64 characters of SAS variable labels are written to a Microsoft Access
or a Microsoft Excel file.
DBMAX_TEXT
Determines the length of a very long data source character data type that is read into SAS or written from
SAS when you are using a SAS/ACCESS engine.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
DBMAX_TEXT=integer
Syntax Description
integer
is a number between 1 and 32,767.
Details
This option applies to reading, appending, and updating rows in an existing table. It does
not apply when you are creating a table.
DBMAX_TEXT= is typically used with a very long character data type.
Although you can specify a value less than 256, it is not recommended for reading data
from a Microsoft Access database.
See Also
To assign this option to a group of tables, use the DBMAX_TEXT= option specified in
“LIBNAME Options” on page 121.
DBNULL 195
DBNULL
Specifies whether NULL is a valid value for the specified columns when a table is created.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: YES
Syntax
DBNULL=
(<column-name-1> =YES|NO
<column-name-n> =YES|NO
<_ALL_> =YES|NO)
Syntax Description
YES
specifies that a NULL value is valid for the specified columns.
NO
specifies that a NULL value is not valid for the specified columns.
Details
this option is valid only for creating data source tables. If you specify more than one
column name, the names must be separated with spaces.
The DBNULL= option processes values from left to right. If you specify a column name
twice, or if you use the _ALL_ value, the last value overrides the first value specified for
the column.
Note: only the Access engine supports this option. The Excel engine does not support
this option.
In this example, all columns in the new MyDBLib.MyDept3 table except for the Jobcode
column are prevented from accepting null values. If the Employees table contains any
null values in any column other than the Jobcode column, the DATA step fails.
DATA mydblib.mydept3(DBNULLl=(_ALL_=no jobcode=YES));
SET mydblib.employees;
RUN;
196 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
DBNULLKEYS
Controls the format of the WHERE clause when you use the DBKEY data set option.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: LIBNAME setting
Syntax
DBNULLKEYS= YES | NO
Details
If there might be NULL values in the transaction table or the master table for the
columns that you specify in the DBKEY option, use DBNULLKEYS=YES. When you
specify DBNULLKEYS=YES, and specify a column that is not defined as DBKEY=
NOT NULL, SAS generates a WHERE clause that finds NULL values.
If you specify DBKEY=COLUMN and COLUMN is not defined as NOT NULL, SAS
generates a WHERE clause.
Example:
WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)));
SAS generates the WHERE clause once and uses it for any value, NULL, or NOT
NULL in the column. This syntax can be much less efficient than the shorter form of the
WHERE clause. When you specify DBNULLKEYS=NO, or specify a column that is
NOT NULL in the DBKEY= option, SAS generates a simple WHERE clause.
If there are no NULL values in the transaction or master table for the columns, use
DBNULLKEYS=NO. If you specify DBNULLKEYS=NO and DBKEY=COLUMN,
SAS generates a shorter form of the WHERE clause. SAS generates the WHERE clause
even if the column DBKEY specifies is defined as NOT NULL.
WHERE (COLUMN = ?)
See Also
• “DBKEY” on page 109
• “LIBNAME Options” on page 121
DBSASLABEL
Specifies whether SAS/ACCESS saves the data source's column names as SAS label names.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: COMPAT
DBTYPE 197
Syntax
DBSASLABEL= COMPAT | NONE
Syntax Description
COMPAT
specifies that SAS/ACCESS saves the data source's column names as SAS label
names. This is compatible to the previous SAS releases.
NONE
specifies that SAS/ACCESS does not save the data source's column names as SAS
label names. SAS label names are left as NULLs.
Details
This option is valid only while you are writing data into SAS from a data source.
DBSASTYPE
Specifies data type(s) to override the default SAS data type(s) during input processing of data.
Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESS
software)
Default: none
Syntax
DBSASTYPE=(<column-name-1> =<SAS data-type> ...<column-name-n> =
<SAS data-type> )
Syntax Description
column-name
specifies a data source column name.
SAS data-type
specifies a SAS data type. SAS data types include CHAR(n), NUMERIC,
DATETIME, DATE, TIME.
Details
By default, SAS/ACCESS converts each data source data type to a SAS data type during
input processing. When you need a different data type, you can use this option to
override the default and assign a SAS data type to each specified data source column.
Note: Some conversions might not be supported. If a conversion is not supported, SAS
prints an error to the log.
DBTYPE
Specifies a data type to use instead of the default data source data type when SAS creates a data source
table.
198 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
Syntax
DBTYPE=(<column-name-1> =<data-source-type> ...
<column-name-1> =<data-source-type> )
Syntax Description
column-name
specifies a data source column name.
data-source-type
specifies a data source data type. See the documentation for your SAS/ACCESS
interface for the default data types for your data source.
Details
By default, SAS/ACCESS converts each SAS data type to a predetermined data source
data type when it writes data to your data source. When you need a different data type,
use DBTYPE= to override the default data type chosen by the SAS/ACCESS engine.
ERRLIMIT
Specifies the number of errors that are allowed before SAS stops processing and issues a rollback.
Valid in: DATA and PROC steps
Default: 1
Syntax
ERRLIMIT=integer
Syntax Description
INTEGER
is a positive integer that represents the number of errors after which SAS stops
processing and issues a rollback.
Details
SAS calls the data source to issue a rollback after a specified number of errors occurs
during the processing of inserts, deletes, updates, and appends. If ERRLIMIT= is set to
INSERTBUFF 199
0, SAS processes all rows, regardless of the number of errors that occur. The SAS log
displays the total number of rows processed and the number of failed rows, if applicable.
The DBCOMMIT= option overrides the ERRLIMIT= option. If you specify a nonzero
value for the DBCOMMIT= option, rollbacks affected by the ERRLIMIT= option might
not be complete. Records already committed by DBCOMMIT= option are not processed
again.
Note: This option cannot be used from a SAS client session in a SAS/SHARE
environment.
See Also
“DBCOMMIT” on page 105
INSERT_SQL
Determines the method to use to insert rows into a data source.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
INSERT_SQL=YES | NO
Syntax Description
YES
specifies that the SAS/ACCESS engine uses the data source's SQL insert method to
insert new rows into a table.
NO
specifies that the SAS/ACCESS engine uses an alternate (data source-specific)
method to add new rows to a table.
See Also
To assign this option to a group of tables, use the INSERT_SQL= option specified in
“LIBNAME Options” on page 121.
INSERTBUFF
Specifies the number of rows in a single insert.
200 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
Syntax
INSERTBUFF=number-of-rows
Syntax Description
number-of-rows
specifies the number of rows to insert. The value must be a positive integer.
Details
SAS allows the maximum number of rows that is allowed by the data source. The
optimal value for this option varies with factors such as network type and available
memory. You might need to experiment with different values to determine the best value
for your site.
When you assign a value greater than INSERTBUFF=1, the SAS notes indicating
success or failure of the insert operation might be incorrect. These notes are generated
for a single insert. This is also true, when multiple inserts are performed.
Note: PC Files Server does not support INSERTBUFF= option with a value higher than
1 for writing data to Excel. It ignores this option when writing data to Excel.
If the DBCOMMIT= option is specified with a value that is less than the value of
INSERTBUFF=, then DBCOMMIT= overrides INSERTBUFF= option.
Note: When you are inserting with the VIEWTABLE window or the FSEDIT or
FSVIEW procedure, use INSERTBUFF=1 to prevent the data source interface from
trying to insert multiple rows. These features do not support inserting more than one
row at a time.
See Also
• “DBCOMMIT” on page 105
• “Overview of Data Set Options” on page 103
NULLCHAR
Indicates how SAS character missing values are handled during insert, update, and DBKEY= processing.
Valid in: DATA and PROC steps
Default: SAS
Syntax
NULLCHAR= YES | NO
NULLCHARVAL 201
Syntax Description
YES
indicates that character missing values in SAS data sets are treated as NULL values
if the data source allows them. Otherwise, an error is returned.
NO
indicates that character missing values in SAS data sets are treated as the
NULLCHARVAL= value, regardless of whether the data source allows NULLs for
the column.
Details
This option affects insert and update processing and also applies when you use the
DBKEY= option.
in conjunction with the NULLCHARVAL= data set option, NULLCHARVAL=
determines what is inserted when NULL values are not allowed.
All SAS numeric missing values (represented in SAS as .) are treated by the data source
as NULLs.
See Also
“DBKEY” on page 109
NULLCHARVAL
Defines the character string that replaces SAS character missing values during insert, update, and
DBKEY= processing.
Valid in: DATA and PROC steps
Default: a blank character
Syntax
NULLCHARVAL=<'character-string'>
Details
This option affects insert and update processing and also applies when you use the
option.
This option works with the NULLCHAR= option. NULCHAR= determines whether a
SAS character NULL value is treated as a NULL value.
If NULLCHARVAL= is longer than the maximum column width, one of these actions
occurs:
• The string is truncated if DBFORCE=YES.
• The operation fails if DBFORCE=NO.
See Also
"DBKEY=" on page 109
202 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
READBUFF
Specifies the number of rows of data to read into the buffer.
Valid in: DATA and PROC steps
Default: LIBNAME option setting
Syntax
READBUFF=<number-of-rows>
Syntax Description
number-of-rows
is the maximum value that is allowed by the data source.
Details
This option improves performance by specifying a number of rows that can be held in
memory for input into SAS. Buffering data reads can decrease network activities and
increase performance. Because SAS stores the rows in memory, higher values for
READBUFF= use more memory. If too many rows are selected at once, then the rows
that are returned to the SAS application can be out of date.
When READBUFF=1, only one row is retrieved at a time. The higher the value for
READBUFF=, the more rows the SAS/ACCESS engine retrieves in one fetch operation.
ROWSET_SIZE is an alias for this option.
See Also
To assign this option to a group of tables, use the READBUFF= option as specified in
“LIBNAME Options” on page 121.
SASDATEFMT
Changes the SAS date format of a data source column.
Valid in: DATA and PROC steps
Default: none
Syntax
SASDATEFMT=(<data-source-date-column-1> =<SAS date-format> ...
<data-source-date-column-n> =<SAS date-format> )
Syntax Description
data-source-date-column
specifies the name of a date column in a data source table.
SASDATEFMT 203
SAS date-format
specifies a SAS date format that has an equivalent informat. For example,
DATETIME21.2 is both a SAS format and informat, so it is valid for the SAS date-
format argument.
Details
If the date format of a SAS column does not match the date format of the corresponding
data column, convert the SAS date values to appropriate values. The SAS DATEFMT=
option enables you to convert date values from a SAS date format to different SAS date
format.
Use SAS DATEFMT= to prevent date type mismatches under these circumstances:
• during input operations to convert data source date values to the correct SAS DATE,
TIME, or DATETIME values
• during output operations to convert SAS DATE, TIME, or DATETIME values to the
correct data source date values
If the SAS date format and the data source date format match, this option is not needed.
The default SAS date format is data source-specific and is determined by the data type of
the data source column. See the documentation for your SAS/ACCESS interface.
Note: For non-English date types, SAS automatically converts the data to the SAS type
of NUMBER. The SAS DATEFMT= option does not currently handle these date
types. You can use a PROC SQL view to convert the source data to a SAS date
format, as you retrieve the data. You can also use a format statement in other
contexts.
204 Chapter 15 • LIBNAME Statement for PCFILES Engine on Linux, UNIX, and Microsoft Windows
205
Chapter 16
Pass-Through Facility: PCFILES
on Linux, UNIX, and Microsoft
Windows
Dictionary
Syntax
PROC SQL option(s)
CONNECT TO data-source-name AS alias
( CONNECT statement-arguments
DATABASE connection-arguments )
DISCONNECT FROM data-source-name
EXECUTE data source-specific-SQL-statement BY data source-name | alias
SELECT column-list FROM CONNECTION TO data-source-name | alias (data-source-query)
Details
You can use the component with the PROC SQL SELECT statement to query data from
a data source.
Return Codes
As you use the PROC SQL statements that are available in the pass-through facility, any
error conditions are written to the SAS log. The pass-through facility generates return
codes and messages that are available to you through the following two SAS macro
variables:
SQLXRC
contains the data source return code that identifies the data source error.
SQLXMSG
contains descriptive information about the data source error that is generated by the
data source.
The contents of the SQLXRC and SQLXMSG macro variables are printed in the SAS
log using the %PUT macro. They are reset after each pass-through facility statement has
been executed.
CONNECT Statement
Establishes a connection with the data source.
Valid in: PROC SQL statement
Syntax
CONNECT TO data-source-name
CONNECT Statement 207
CONNECT TO option(s)
Optional Arguments
data-source-name
Specifies the data source to which you want to connect. Because this method
requires connecting through a PC Files Server, you must use PCFILES as your data
source. You can also specify an optional alias in the CONNECT statement.
alias
specifies an optional alias for the connection that has 1 to 32 characters. If you
specify an alias, the keyword AS must appear before the alias. If an alias is not
specified, the data source name is used as the name of the pass-through connection.
connect-statement-arguments
specifies arguments that indicate whether you can make multiple connections (shared
connections, unique connections, and so on) to the database.
database-connection-arguments
specifies the data source-specific arguments that are needed by PROC SQL to
connect to the data source. These arguments are not required. The default behavior
opens a dialog box with prompts to specify connection information.
Details
Overview
The CONNECT statement establishes a connection with the data source. You establish a
connection to send data source-specific SQL statements to the data source or to retrieve
data source data. The connection remains in effect until you issue a DISCONNECT
statement or terminate the SQL procedure. See “DISCONNECT Statement” on page
137.
To connect to a data source using the pass-through facility, complete the following steps:
1. Initiate a PROC SQL step.
2. Use the pass-through facility CONNECT statement with the PC files engine name
and then assign an alias if you want.
3. Specify any arguments needed to connect to the database.
4. Specify any attributes for the connection.
The CONNECT statement is optional for some data sources. However, if you do not
specify it, default values for all database connection arguments are used.
Any return code or message that is generated by the data source is available in the macro
variables SQLXRC and SQLXMSG after the statement executes. See “Return Codes” on
page 130 for more information about these macro variables.
Note: This ODBC data source must be defined on the PC where the PC Files Server
is currently running.
CONNECT_STRING= connection-string
specifies connection options for your data source or database. Separate multiple
options with semicolons. This is an advanced connection method that you should use
only when you know the exact syntax of all connection options that the ODBC driver
requires for a successful connection.
PATH= path-for-file
specifies the data source file location for the Microsoft Access database file or
Microsoft Excel workbook file.
PORT= port-number
The port or service name on the PC that the SAS PC Files Server is listening on. This
port or service name is displayed on the SAS PC Files Server window when it is
started on the PC. This is a required field when connecting to the PC Files Server for
data.
Alias: SERVICE | SERVICE_NAME
Default: 9621
SERVER= pc-server-host-name
specifies the computer name of the PC on which you started the PC Files Server.
This name is required by UNIX users to connect to this server machine and is
reflected on the server control panel. This is a required field when connecting to the
PC Files Server for data.
You can specify this host name as a simple computer name (for example, wxp320), a
fully qualified network name (for example, wxp320.domain.com), or an IP
address.
Note: Omitting the SERVER= option on Microsoft Windows clients invokes
Autostart.
SERVERUSER= 'domain\server-user-name'
specifies the domain name and User ID for the PC running PC Files Server. Always
enclose the value in quotation marks. Otherwise, the backslash can be misinterpreted
by the SAS parser.
Alias: SERVERUID
Notes:
If you are not on a domain, omit the domain name and the backslash.
Use the USER= option for database user IDs.
SERVERPASS= 'server-user-password'
specifies the password for the PC Files Server for the user ID given. If the account
has no password, omit this option. Always enclose the value in quotes in order to
preserve the case of the password.
Alias: SERVERPASSWORD | SERVERPW | SERVERPWD
Notes:
Passwords are generally case sensitive.
Use the PASSWORD= option for database passwords.
SSPI= YES | NO
enables the PC Files Server to allow Integrated Windows Authentication. This is a
mechanism for the Windows client and server to exchange credentials.
Default: NO
Restriction: Microsoft Windows 64-Bit only.
CONNECT Statement 209
Note: SSPI can also be enabled by specifying the –SSPI option on the SAS
command line.
DBPASSWORD= database-password
enables you to access your file if you have database-level security set in your MDB
file. A database password is case sensitive, and you can define it instead of user-level
security.
Restriction: Microsoft Access only.
DBSYSFILE= workgroup-information-file
contains information about the users in a workgroup based on information that you
define for your Microsoft Access database. Any user and group accounts or
passwords that you create are saved in the new workgroup information file.
PASSWORD= user-password
specifies a password for the user account, if required by the data source. Passwords
are case sensitive.
MSENGINE= ACE | JET
determines the database engine used for accessing the Microsoft Excel file or
Microsoft Access database. The Microsoft Jet engine is older and supports formats
up to 2003. The Microsoft ACE engine supports Microsoft Excel 2007 and Microsoft
Access 2007 and older formats.
Default: ACE
USER= User ID
specifies a default user account name. The default value is Admin. User names can
be 1 to 20 characters long and can include alphabetic characters, accented characters,
numbers, and spaces. If you have user-level security set in your MDB file, you need
to use this option and the PASSWORD= option to access your file.
VERSION= 2007 | 2003 | 2002 | 2000 | 97 | 95 | 5
sets the version of Microsoft Excel workbook. The default value is 97.
Alias: VER
Restriction: Microsoft Excel only.
Note: You do not need to specify this option for an existing Microsoft Excel file. If
you want to create a new Microsoft Excel workbook file, you can use this option
to specify the version that you want to create. Note that versions 97, 2000, and
2003 of Excel share the same file format. Versions 95 and 5 share a separate file
format.
Note: The default value for this option is different from the LIBNAME option.
COMMAND_TIMEOUT= number-of-seconds
specifies the number of seconds before a data source command times out.
Alias: TIMEOUT
Default: 0 (no time-out)
CONNECTION=SHARED | GLOBAL
specifies whether multiple CONNECT statements for a data source can use the same
connection. The CONNECTION= option enables you to control the number of
connections, and therefore transactions, that your SAS/ACCESS engine executes and
supports for each CONNECT statement.
SHARED
specifies that the CONNECT statement makes one connection to the DBMS.
Only pass-through statements that use this alias share the connection.
GLOBAL
specifies that multiple CONNECT statements can share the same connection to
the DBMS.
• The CONNECT statements must use identical values for the
CONNECTION= option.
• The CONNECT statement must use identical values for the
CONNECTION_GROUP= option.
• Database connection arguments must be identical.
Default: SHARED
CONNECTION_GROUP= connection-group
causes operations against multiple librefs to share a connection to the data source.
Also causes operations against multiple pass-through facility CONNECT statements
to share a connection to the data source.
CURSOR_TYPE= DYNAMIC | FORWARD_ONLY | KEYSET_DRIVEN | STATIC
specifies the cursor type for read-only cursors and for cursors to be updated.
DYNAMIC
specifies that the cursor reflects all changes that are made to the rows in a result
set as you move the cursor. The data values and the membership of rows in the
cursor can change dynamically on each fetch. This is the default for the DB2
UNIX, PC files, and Microsoft SQL Server interfaces.
FORWARD_ONLY
specifies that the cursor behaves like a DYNAMIC cursor, except that it supports
only fetching the rows sequentially.
KEYSET_DRIVEN
specifies that the cursor determines which rows belong to the result set when the
cursor is opened. However, changes that are made to these rows are reflected as
you scroll around the cursor.
STATIC
specifies that the complete result set is built when the cursor is opened. No
changes that are made to the rows in the result set after the cursor is opened are
reflected in the cursor. Static cursors are read-only.
Alias: CURSOR
Default: None
CONNECT Statement 211
DBMAX_TEXT= n
specifies an integer between 1 and 32,767 that indicates the maximum length for a
character string. Longer character strings are truncated. This option applies only
when you are reading, appending, and updating Microsoft Access or Excel character
data from SAS.
Default: 1,024
Note: Although you can specify a value less than 256, it is not recommended.
DEFER= NO | YES
enables you to specify when the CONNECT statement occurs.
NO
specifies that the connection to the data source occurs when the libref is assigned
by a LIBNAME statement.
YES
specifies that the connection to the data source occurs when a table in the data
source is opened.
Default: NO
READBUFF= number-of-rows
specifies the number of rows to use when you are reading data from a data source.
Setting a higher value for this option reduces I/O and increases performance, but also
increases memory usage. In addition, if too many rows are read at once, values
returned to SAS might be out of date.
Alias:
ROWSET=
ROWSET_SIZE=
Default: 1
STRINGDATES= YES | NO
specifies whether datetime values are read from the data source as character strings
or as numeric date values. STRINGDATES= is not available as a data set option.
YES
specifies that SAS/ACCESS reads datetime values as character strings.
NO
specifies that SAS/ACCESS reads datetime values as numeric date values.
Alias: STRDATES
Default: NO
212 Chapter 16 • Pass-Through Facility: PCFILES on Linux, UNIX, and Microsoft Windows
USEDATE= YES | NO
specifies whether to assign the DATE. format or the DATETIME. format for
datetime columns in the data source table while importing data from a Microsoft
Access database or a Microsoft Excel workbook.
YES
specifies that the DATE. format is assigned to datetime columns in the data
source table.
NO
specifies that the DATETIME. format is assigned for datetime columns in the
data source table.
Alias: USE_DATE | USE_DATETYPE
Default: NO
Example
The following example uses the CONNECT statement with the PATH= option to
connect to the Microsoft Access database file, c:\demo.mdb:
PROC SQL;
CONNECT TO PCFILES AS db (SERVER=d2323 PATH=' c:\demo.mdb' );
DISCONNECT Statement
Ends the connection to the data source.
Valid in: SQL procedure.
Syntax
DISCONNECT FROM <data-source-name> <alias>
Syntax Description
Data-source-name
specifies the data-source-name from which you want to disconnect. The
DISCONNECT statement's data-source-name must match the data-source-name that
you specified in the CONNECT statement.
Alias
specifies the data source alias from which you want to disconnect. The
DISCONNECT statement's alias must match the alias that you specified in the
CONNECT statement.
Details
The DISCONNECT statement ends the connection with the data source. If the
DISCONNECT statement is omitted, an implicit DISCONNECT is performed when the
procedure ends. The SQL procedure continues to execute until you submit a QUIT
statement, a SAS procedure, or a DATA step.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the
SAS log using the macro. The contents are reset after each pass-through facility
statement is executed.
EXECUTE Statement 213
EXECUTE Statement
Sends data source-specific, non-query SQL statements to the data source.
Valid in: SQL procedure steps.
Syntax
EXECUTE (data-source-specific-SQL-statement(s))
BY
<data-source-name> <alias>
Syntax Description
Data-source-specific-SQL-statements
specifies a dynamic non-query, data source-specific SQL statement. Depending on
your data source, the SQL statement can be case sensitive. The statement is passed to
the data source exactly as you type it.
CREATE
creates a data source table, view, index, or other data source object, depending on
how the statement is specified.
DELETE
deletes rows from a data source table.
DROP
drops a data source table, view, or other data source object, depending on how
the statement is specified.
GRANT
gives users the authority to access or modify objects such as tables or views.
INSERT
inserts rows to a data source table.
REVOKE
revokes the access or modification privileges that were given to users by the
GRANT statement.
UPDATE
updates the data in the specified columns of a row in a data source table.
Requirements:
At least one statement is required.
The statement must be enclosed in parentheses.
214 Chapter 16 • Pass-Through Facility: PCFILES on Linux, UNIX, and Microsoft Windows
Data-source-name
specifies the data-source-name to which you direct the data source-specific SQL
statements. The EXECUTE statement's data-source-name must match the data-
source-name specified in the CONNECT statement.
Alias
specifies the data source alias that was defined in the CONNECT statement. The
EXECUTE statement's alias must match the alias that you specified in the
CONNECT statement.
Details
The EXECUTE statement sends dynamic non-query, data source-specificSQL
statements to the data source and processes those statements. The EXECUTE statement
cannot be stored as part of a pass-through facility query in an SQL view.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the
SAS log using the macros. The contents are reset after each pass-through facility
statement is executed.
CONNECTION TO Component
Retrieves and uses data source data in a PROC SQL query or view.
Valid in: SQL procedure STEP statements.
Syntax
CONNECT TO a data- source AS alias (connect statement arguments)
(database connection-options)
ALIAS
DATABASE CONNECTION ARGUMENTS
DATA SOURCE NAME
CONNECTION COMPONENT
CONNECTION TO Component 215
Optional Arguments
ALIAS
specifies the data source alias for the connection. If you specify an alias, the keyword
AS must appear before the alias.
Restriction: ALIAS is not supported if the CONNECT statement is omitted.
Requirement: The range of the ALIAS is between 1 and 32 characters.
Note: The data source name is used as the name of the pass-through connection if an
alias is not specified.
CONNECTION COMPONENT
specifies arguments that indicate whether you can make multiple connections, shared
connections, or unique connections, to the database.
DATA SOURCE NAME
specifies the data source name to which you want to connect and direct the data
source-specific SQL statements.
Requirement: You must use back quotation marks ( ` ), not single (forward)
quotation marks, to enclose any data source name that contains a space.
Note: The data source name becomes the name of the pass-through connection if an
alias is not specified.
DATABASE CONNECTION ARGUMENTS
specifies the data source-specific arguments to the pass-through facility that are
needed by the SQL procedure to connect to a data source.
NO prompting is not available. You must specify the data source as a physical
filename or complete path.
216 Chapter 16 • Pass-Through Facility: PCFILES on Linux, UNIX, and Microsoft Windows
Alias: UDL_FILE
See: Microsoft Data Link API documentation.
DBSYSFILE= workgroup-information-file
specifies the workgroup information file. This file contains a collection of
information defined for the Microsoft Access database. User, group accounts, and
passwords that you create are saved in the workgroup information file.
Alias: SYSTEMDB
Restriction: Microsoft Access database files only.
PASSWORD= user-password
specifies a password required by the data source for the user account.
Alias: PWD | PW | PASS | PASSWORD
Note: Passwords are case sensitive.
USER= user-id
specifies a user account name, if one is required to connect to the data source. For
Microsoft Access, if you have user-level security set on your .mdb file, you need to
use the USER= and PASSWORD= options to access your file.
Alias: UID
Restriction: Microsoft Access database files only.
Note: Use the SERVERUSER= option to connect to a server.
CONNECTION TO Component 217
Details
The CONNECTION component specifies the data source connection to use or to create.
CONNECTION enables you to retrieve data source data directly through an SQL
procedure query.
• The CONNECTION component can be used in any FROM clause, including those in
nested queries (subqueries).
• You can store a pass-through facility query in an SQL view and then use that view in
SAS programs.
• When you create an SQL view, any options that you specify in the corresponding
CONNECTION statement are stored too. Thus, when the SQL view is used in a SAS
program, SAS can establish the appropriate connection to the data source.
• Because external data sources and SAS have different naming conventions, some
data source column names might be changed when you retrieve data source data
through the CONNECTION component.
Chapter 17
Special Query Support
Part 5
Chapter 18
The ACCESS Procedure for PC Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Chapter 19
The DBLOAD Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Chapter 20
File-Specific Reference for the ACCESS and DBLOAD Procedures . .
259
224
225
Chapter 18
The ACCESS Procedure for PC
Files
As the table indicates, you can create one or more access descriptors and view
descriptors in one execution of PROC ACCESS, or you can create the descriptors in
separate executions.
See "CREATE Statement" on page 231 for additional information.
Overview
There are two types of descriptor files: access descriptors and view descriptors.
Access Descriptors
An access descriptor holds essential information about the structure of the PC file that
you want to access. For example, you can access the file's format and name, its database
field or column names, and its data types. Access descriptors can also contain the
corresponding SAS information such as the SAS variable names and formats. Typically,
you have only one access descriptor for each PC file.
An access descriptor describes only a PC file format and contents to SAS, that is, it is a
master description file of the PC file for SAS. You cannot use an access descriptor in a
SAS program. Instead, use an access descriptor to create other SAS files, called view
descriptors, that you use in SAS programs.
When you create an access descriptor, the default setting for a SAS variable name is a
blank. However, if you have previously entered or modified any of the SAS variable
names, the RESET statement resets the modified names to the default names that are
generated by the ACCESS procedure. How the default SAS variable names are set
depends on whether you included the ASSIGN statement. If you omitted ASSIGN or set
it to NO, the default names are blank. If you set ASSIGN= YES, the default names are
the first eight characters of each PC file column name.
228 Chapter 18 • The ACCESS Procedure for PC Files
The current SAS variable format is also reset to the default SAS format, which was
determined from the column's data type. Any columns that were previously dropped, but
that are specified in the RESET statement, become available; they can be selected in
view descriptors that are based on this access descriptor.
SAS/ACCESS descriptor files are the tools that the ACCESS procedure uses to establish
a connection to a PC file. There are two types of descriptor files: access descriptors and
view descriptors. Use the ACCESS procedure to create descriptors.
View Descriptors
A view descriptor defines some or all of the data that is described by one access
descriptor (and, therefore, one PC file). For example, you might want to use only three
of nine possible database columns and only some of the rows in a PC file. The view
descriptor enables you to do this by selecting the database fields or columns that you
want to use and specifying criteria to retrieve only the rows that you want. Typically,
you create several view descriptors based on one access descriptor, where each view
descriptor selects a different subset of the PC files data.
A view descriptor is a SAS data set or, more specifically, a SAS data view. You use a
view descriptor in a SAS program much as you would any SAS data set. For example,
you can specify a view descriptor in the DATA= statement of a SAS procedure or the
SET statement of a DATA step. You can use a view descriptor in a SELECT statement
of the SQL procedure to join view descriptor data with SAS data, for example.
You can use a view descriptor to update data directly in some of the PC file formats,
such as the DBF file format.
In some cases, you might also want to create a SAS data file from data stored in a PC
file. Using a view descriptor to copy PC files data into a SAS data file is called
extracting the data.
When you create a view descriptor, the RESET statement clears any columns that were
included in the SELECT statement.
When creating the view descriptor, if you reset a SAS variable and select it again within
the same procedure execution, the SAS variable names and formats are reset to their
default values. The defaults are generated from the column names and data types. This
applies only if you have omitted the ASSIGN statement or set the value to NO when you
created the access descriptor.
If you specified ASSIGN= YES when you created the access descriptor, the RESET =
option has no effect on the view descriptor.
Use a view descriptor to update data directly in some of the PC file formats, such as the
DBF file format.
Create a SAS data set from data stored in a PC file. When a view descriptor is used to
copy PC files data into a SAS data set is called extracting the data.
• For added security, you can assign a password to the extracted SAS data file.
Note: You can create one or more access descriptors and view descriptors in one
execution of PROC ACCESS, or you can create the descriptors in separate
executions.
Syntax
PROC ACCESS <option(s)>
Optional Arguments
DBMS= pc-file-format
specifies the PC file format that you want to access. Specify DBMS= DBF for DBF
files, DBMS= DIF for DIF files, DBMS= WK1 | WK3 | WK4 for WKn files, or
DBMS=XLS for XLS files.
Valid in: PROC SQL
Restriction: The ACCESS Procedure is supported only in V6 SAS.
VIEWDESC= libref.view-descriptor
specifies a view descriptor as input for the OUT= option.
See: OUT=
OUT= libref.member-name
specifies a SAS data file. When VIEWDESC= and OUT= are used together, you can
write data that is accessed from the view descriptor to the SAS data set that is
specified in OUT= option.
PROC ACCESS
VIEWDESC=vlib.invq4
OUT=dlib.invq4;
RUN;
See:
Chapter 5, “The EXPORT Procedure,” on page 21
Chapter 4, “The IMPORT Procedure,” on page 13
CREATE Statement 231
ASSIGN Statement
Indicates whether SAS variable names and formats are automatically generated.
Syntax
ASSIGN= YES | NO | Y | N
Details
The ASSIGN statement indicates whether SAS variable names and formats are
automatically generated. Where long names must be shortened to the SAS length limit of
eight characters, variable names are automatically generated.
An editing statement such as ASSIGN appears after the CREATE and database-
description statements. See "Create Statement" on page 231 for additional information.
You can use the value NO (or N) to modify SAS variable names and formats when you
create an access descriptor. Use NO (or N) when you create view descriptors that are
based on this access descriptor. When creating an access descriptor, use the RENAME
statement to change SAS variable names. Use the FORMAT statement to change SAS
formats.
Specify a YES (or Y) value for this statement to generate unique SAS variable names
from the first eight characters of the PC file column names. With YES, you can change
the SAS variable names only in the access descriptor. The SAS variable names that are
saved in an access descriptor are always used when view descriptors are created from the
access descriptor. You cannot change the variable names in the view descriptors.
SAS variable names are generated as follows:
• If the column name is longer than eight characters, SAS uses only the first eight
characters. If truncating results in duplicate names, numbers are appended to the
ends of the names to prevent duplicate names.
• If the column name in the PC file contains blank characters, SAS ignores it.
• If the column name in the PC file starts with a digit (0 through 9), SAS adds the
character Z before it.
• If the column name contains characters that are invalid in SAS names (including
national characters), SAS replaces the invalid characters with underscores (_).
When the SAS/ACCESS interface encounters the next CREATE statement to create an
access descriptor, the ASSIGN statement is reset to the default NO value.
CREATE Statement
Creates a SAS/ACCESS descriptor file.
Requirement: This statement is required.
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments access descriptor or view descriptor
232 Chapter 18 • The ACCESS Procedure for PC Files
Syntax
CREATE libref.descriptor-name. ACCESS | VIEW
Details
Overview
Use CREATE to create an access or view descriptor for a PC file that you want to access
from SAS. To access a particular PC file of a supported type, you must create first an
access descriptor, and then one or more view descriptors based on the access descriptor.
The descriptor name has three parts, separated by periods. The libref identifies a SAS
library, which is associated with a directory on the local system disk where the
descriptor is created. The libref must have been created already using the LIBNAME
statement. The descriptor-name is the name of the descriptor to be created. The third
part is the descriptor type. Specify ACCESS for an access descriptor or VIEW for a view
descriptor.
You can use the CREATE statement as many times as necessary in one procedure
execution. That is, you can create multiple access descriptors, as well as one or more
view descriptors based on these access descriptors, within the same execution of the
ACCESS procedure. Or, you can create access descriptors and view descriptors in
separate executions of the procedure.
You can use the CREATE and the UPDATE in the same PROC ACCESS block with
one restriction: a CREATE statement for a view descriptor should not follow an
UPDATE statement.
The order of the statements within the database-description and editing groups
sometimes matters; see the individual statement descriptions for more information.
Note: Altering a PC file that has descriptor files defined on it might cause the descriptor
files to be out-of-date or invalid. If you recreate a file and add a new column to the
file, an existing access descriptor defined does not show that column, but the
descriptor can still be valid. If you recreate a file and delete an existing column from
the file, the descriptor is invalid. If the deleted column is included in a view
CREATE Statement 233
descriptor that is used in a SAS program, the program fails and an error message is
written to the SAS log.
Examples
fibersize e20.13
width e16.9;
RUN;
CREATE vlib.emp1204.view;
/* create view descriptor */
SELECT empid lastname hiredate salary
dept gender birthdate;
FORMAT empid 6.
salary dollar12.2
jobcode 5.
hiredate datetime7.
birthdate datetime7.;
SUBSET WHERE jobcode=1204;
RUN;
DROP Statement
Drops a column from a descriptor.
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments access descriptor, view descriptor RESET,
SELECT, UPDATE
FORMAT Statement 235
Syntax
DROP 'column-identifier1' ... 'column-identifierN';
Details
The DROP statement drops the specified column from an access descriptor. The column
cannot be selected for a view descriptor that is based on the access descriptor. However,
the specified column in the PC file remains unaffected by this statement.
You can specify the DROP statement only when you create or update an access
descriptor or when you update a view descriptor. DROP is not allowed when you create
a view descriptor. When you use the UPDATE statement, you can specify DROP to
remove a column from the view descriptor. However, the specified column in the PC file
remains unaffected by the DROP statement.
An editing statement, such as DROP, must follow the CREATE and database-
description statements when you create an access descriptor.
See "Create Statement" on page 231 for additional information.
The column-identifier argument can be the column name or the positional equivalent
from the LIST statement. This is the number that represents column placement in the
access descriptor or view descriptor. To drop the third and fifth columns, submit this
statement:
DROP 3 5;
FORMAT Statement
Changes a SAS format for a PC file column.
Notes: When you use the FORMAT statement with access descriptors, the FORMAT
statement also re-selects columns that were previously dropped with the DROP
statement.
for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments access descriptor or view descriptor ASSIGN,
DROP, RESET
Syntax
FORMAT | FMT 'column-identifier1' SAS format-name 'column-identifierN' SAS format-name
Details
The Format Statement changes a SAS format for a PC file column.
236 Chapter 18 • The ACCESS Procedure for PC Files
The FORMAT statement changes a SAS variable format from its default format. The
default SAS variable format is based on the data type and format of the PC file column.
(See your PC file's chapter for information about the default data types and formats that
SAS assigns to PC files data.)
An editing statement, such as FORMAT, must follow the CREATE statement and the
database-description statements when you create a descriptor.
See "Create Statement" on page 231 for additional information .
The column-identifier argument can be either the column name or the positional
equivalent from the LIST statement. This is the number that represents the column's
place in the access descriptor. To associate the DATE9. format with the BIRTHDATE
column, and the second column in the access descriptor, submit this statement:
FORMAT 2=DATE9. birthdate=DATE9.;
The column identifier is specified on the left and the SAS format is specified on the right
of the expression. The equal sign is optional. If the column name contains lowercase
characters, special characters, or national characters, enclose the name in quotation
marks. You can enter formats for as many columns as you want in one FORMAT
statement.
You can use the FORMAT statement with a view descriptor only if the ASSIGN
statement that was used when creating the access descriptor was specified with the NO
value.
LIST Statement
Lists columns in the descriptor and gives information about them.
Default: ALL
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments access descriptor or view descriptor
Syntax
LIST ALL | VIEW |'column-identifier'
Required Arguments
ALL
lists all columns in the PC file, the positional equivalents, the SAS variable names,
and the SAS variable formats that are available for the access descriptor. When you
are creating an access descriptor, *NON-DISPLAY* appears next to the column
description for any column that has been dropped. When you are creating a view
descriptor, *SELECTED* appears next to the column description for columns that
you have selected for the view.
VIEW
lists all columns that are selected for the view descriptor, along with their positional
equivalents, their SAS names and formats, and any sub-setting clauses. Any columns
that were dropped in the access descriptor are not displayed. The VIEW argument is
valid only for a view descriptor.
column-identifier
lists the specified column name, its positional equivalent, its SAS variable name and
format, and whether the column has been selected. If the column name contains
PATH Statement 237
Details
The LIST statement lists columns in the descriptor along with information about the
columns. You can use the LIST statement when creating an access descriptor or a view
descriptor. The LIST information is written to your SAS log.
If you use an editing statement, such as LIST, it must follow the CREATE statement and
the database-description statements when you create a descriptor. You can specify LIST
as many times as you want while creating a descriptor; specify LIST last in your PROC
ACCESS code to see the entire descriptor. Or, if you are creating multiple descriptors,
specify LIST before the next CREATE statement in order to list all information about
the descriptor that you are creating.
The LIST statement can take one or more of these arguments:
You can use one or more of these previously described options in a LIST statement, in
any order.
MIXED Statement
Determines whether to convert numeric data values in a column to their character representation when the
corresponding SAS variable is expecting a character value.
Restriction: The MIXED= statement is an editing statement and must follow the CREATE
statement and any database descriptions when you create an access descriptor.
Note: For WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under Windows
operating environments
Syntax
MIXED= YES | NO | Y | N
Details
You use the MIXED= option with WKn and XLS files if you have both numeric and
character data in a column. Specifying YES allows both numeric and character data to be
displayed as SAS character data. NO, the default, treats any data in a column that does
not match the specified type as missing values.
You can change the default value to YES by setting the SS_MIXED environment
variable. See“Setting Environment Variables for XLS Files” on page 270 for additional
information.
PATH Statement
Specifies the path and filename of the file to access.
238 Chapter 18 • The ACCESS Procedure for PC Files
Syntax
PATH= 'path and filename.PC-file-extension' | fileref 'filename'
Required Arguments
PATH= 'path and filename.PC-file-extension'
specifies the fully qualified path and filename. You must enclose the entire path and
filename in quotation marks, including the appropriate PC file extension, such
as .dbf, .dif, .wk1, .wk3, wk4, .mdb, or .xls. If you omit the file extension,
SAS/ACCESS software supplies it for you.
PATH= 'filename'
specifies the name of a file. The file must be located in your current (default)
directory. If no extension is specified, the SAS/ACCESS interface supplies it for
you. If the filename includes characters that are invalid in SAS names, such as the
dollar sign ($) or if the filename begins with a number, you must enclose the entire
filename in quotation marks.
PATH= fileref
specifies a fileref that references the path and name of the file. (Assigning a fileref
with the FILENAME statement is described in Step-by-Step Programming with Base
SAS Software.
Details
The PATH= statement indicates the path and name of the file that you want to access.
The length of the filename and its other conventions can vary with the operating system.
See the host documentation for your operating environment for more information.
For compatibility, place the PATH= statement immediately after the CREATE statement
and before any other database-description statements when creating access descriptors.
See "Create Statement" on page 231 for additional information.
QUIT Statement
Terminates the procedure.
Alias: EXIT
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments access descriptor or view descriptor
Syntax
QUIT;
Details
The QUIT statement terminates the ACCESS procedure and descriptor creation.
RENAME Statement 239
RENAME Statement
Modifies the SAS variable name.
Note: For DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments, access descriptor or view descriptor ASSIGN,
RESET
Syntax
RENAME= 'column-identifier1' 'SAS variable-name1' , 'column-identifierN' 'SAS variable-name-n'
Details
The RENAME statement enters or modifies the SAS variable name that is associated
with a column in a PC file. Use the RENAME statement when creating an access
descriptor or a view descriptor.
An editing statement, such as RENAME, must follow the CREATE statement and the
database-description statements when you create a descriptor. See "Create Statement" on
page 231 for additional information.
Two factors affect the use of the RENAME statement: whether you specify the ASSIGN
statement when you are creating an access descriptor, and the type of descriptor that you
are creating.
• If you omit the ASSIGN statement or specify it with a NO value, the renamed SAS
variable names that you specify in the access descriptor are retained throughout a
SAS/ACCESS procedure execution. For example, if you rename the Customer
column to CustNum when you create an access descriptor, that column continues to
be named CustNum when you select it in a view descriptor unless a RESET
statement or another RENAME statement is specified.
When creating a view descriptor that is based on this access descriptor, you can
specify the RESET statement or another RENAME statement to rename the variable
again, but the new name applies only in that view. When you create other view
descriptors, the SAS variable names are derived from the access descriptor variable
names.
• If you specify the YES value in the ASSIGN statement, you can use the RENAME
statement to change SAS variable names only while creating an access descriptor.
SAS variable names, and formats that are saved in an access descriptor are always
used when creating view descriptors that are based on it.
The column-identifier argument can be either the column name or the positional
equivalent from the LIST statement. This is the number that represents the column's
place in the descriptor. To rename SAS variables that are associated with the seventh
column and the nine-character FIRSTNAME column in a descriptor, submit this
statement:
RENAME 7 birthdy 'firstname'=fname;
The column name, or positional equivalent is specified on the left side of the expression,
with the SAS variable name on the right side. The equal sign (=) is optional. If the
column name contains lowercase characters, special characters, or national characters,
enclose the name in quotation marks. You can rename as many columns as you want in
one RENAME statement.
240 Chapter 18 • The ACCESS Procedure for PC Files
When you are creating a view descriptor, the RENAME statement automatically selects
the renamed column for the view. If you rename the SAS variable associated with a
column, you do not have to issue a SELECT statement for that column.
When creating an access descriptor, the RENAME statement also re-selects previously
dropped columns that were dropped with the DROP statement.
RESET Statement
Resets PC file columns to their default settings.
Restriction: Not allowed with UPDATE
Interaction: ASSIGN, DROP, FORMAT, RENAME, SELECT
Notes: For DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments, access descriptor or view descriptor, ASSIGN,
DROP, FORMAT, RENAME, SELECT UPDATE
Applies to access descriptor or view descriptor
Syntax
RESET ALL | 'column-identifier1' ... 'column-identifierN'
Required Arguments
ALL
for access descriptors, resets all PC file columns that are defined to their default
names and format settings and re-selects any dropped columns.
For view descriptors, ALL resets all columns that are selected so that no columns are
selected for the view. You can then use the SELECT statement to select new
columns.
See the "SELECT Statement" on page 241.
column-identifier
can be either the column name or the positional equivalent from the LIST statement.
This is the number that represents the column's place in the access descriptor. To
reset the SAS variable name and format associated with the third column, submit this
statement: RESET 3;
If the column name contains lowercase characters, special characters, or national
characters, enclose the name in quotation marks. Reset as many columns as you want
in one RESET statement. The ALL option can also be used to reset all columns.
When creating an access descriptor, the column-identifier is reset to its default name
and format settings. When creating a view descriptor, the specified column is no
longer selected for the view.
Details
The RESET statement resets either the attributes of all columns or the attributes of the
specified columns to their default values. The RESET statement can be used when you
create an access descriptor or a view descriptor, but it is not allowed when you are
updating a descriptor. RESET has different effects on access and view descriptors, as
described below.
SUBSET Statement 241
If you use an editing statement, such as RESET, it must follow the CREATE statement
and the database-description statements when you create a descriptor.
See "CREATE Statement" on page 231 for additional information.
SELECT Statement
Selects PC file columns for the view descriptor.
Requirement: This statement is required.
Note: For DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments view descriptor RESET UPDATE
Syntax
SELECT ALL | 'column-identifier1' , 'column-identifierN';
Details
The SELECT statement specifies which PC file columns in the access descriptor to
include in the view descriptor. This is a required statement, and you can use it only when
you create view descriptors. You cannot use the SELECT statement when you update a
view descriptor.
If you use an editing statement, such as SELECT, it must follow the CREATE statement
when you create a view descriptor.
See "CREATE Statement" on page 231 for additional information.
The SELECT statement can take one or more of these arguments:
ALL
includes in the view descriptor all columns that were defined in the access descriptor
and that were not dropped.
column-identifier
can be either the column name or the positional equivalent from the LIST statement.
This is the number that represents the column's place in the access descriptor on
which the view is based. To select the first three columns, submit this statement:
SELECT 1 2 3;
If the column name contains lowercase characters, special characters, or national
characters, enclose the name in quotation marks. You can select as many columns as
you want in one SELECT statement.
SELECT statements are cumulative within the same view creation. Submit these
SELECT statements to select columns 1, 5, and 6. SELECT 1; SELECT 5 6;
To clear all your selections when creating a view descriptor, use the RESET ALL
statement. You can use another SELECT statement to select new columns.
SUBSET Statement
Adds or modifies selection criteria for a view descriptor.
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments view descriptor
242 Chapter 18 • The ACCESS Procedure for PC Files
Syntax
SUBSET selection-criteria;
Details
Use the SUBSET statement to specify selection criteria when you create a view
descriptor. This statement is optional. If you omit it, the view retrieves all data (rows) in
the PC file.
CAUTION:
An editing statement, such as SUBSET, must follow the CREATE statement
when you create a view descriptor.
TYPE Statement
Changes the expected data types of SAS variables.
Note: for DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under Windows
operating environments
Syntax
TYPE 'column-identifier-1' = C | N <'column-identifier-n'>= C | N;
Details
SAS data sets have two data types: character (C) and numeric (N). Spreadsheet files
have the same two data types: character (for labels and formula strings) and numeric (for
numbers and formulas). Changing the default data type of a SAS variable in a descriptor
file also changes its associated default format in the loaded file.
If you omit the TYPE statement, the database field types are generated from the PC files
data types. You can change as many database field types as you want in one TYPE
statement.
This statement is not available for use with DBF files.
UNIQUE Statement
Generates SAS variable names based on PC file column names.
Alias: UN
Note: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under
Windows operating environments view descriptor ASSIGN UPDATE
Syntax
UNIQUE = YES | NO | Y | N
UPDATE Statement 243
Details
The UNIQUE statement specifies whether the SAS/ACCESS interface generates unique
SAS variable names for PC file columns for which SAS variable names have not been
entered. You cannot use the UNIQUE statement when you are updating a view
descriptor.
An editing statement, such as UNIQUE, must follow the CREATE statement when you
create a view descriptor.
See the "CREATE Statement" on page 231 for more information about the order of
statements. The UNIQUE statement is affected by whether you specified the ASSIGN
statement when you created the access descriptor on which this view is based, as
follows:
• If you specified the ASSIGN= YES option, the UNIQUE= option cannot be used
when creating a view descriptor. YES causes SAS to generate unique names, so
UNIQUE is not necessary.
• If you omitted the ASSIGN statement or specified ASSIGN= NO, resolve any
duplicate SAS variable names in the view descriptor. Use the UNIQUE= option to
generate unique names automatically, or you can use the RENAME= option to
resolve duplicate names yourself.
See the "RENAME Statement" on page 239 for information about that statement.
If duplicate SAS variable names exist in the Access Descriptor that you are using to
creating a View Descriptor, specify the UNIQUE= option to resolve the duplication.
When you specify tUNIQUE= YES, the SAS/ACCESS interface appends numbers to
any duplicate SAS variable names, thus making each variable name unique.
See the "CREATE Statement" on page 231 .
If you specify UNIQUE= NO, the SAS/ACCESS interface continues to allow duplicate
SAS variable names to exist. To create the View Descriptor, resolve duplicate names
before saving.
Note: It is recommended that you use the UNIQUE statement. If you omit it and SAS
encounters duplicate SAS variable names in a view descriptor, your job fails. The
equal (=) sign is optional in the UNIQUE statement.
UPDATE Statement
Updates a SAS/ACCESS descriptor file.
Note: For DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95, file formats under
Windows operating environments access descriptor or view descriptor ASSIGN,
RESET, SELECT, UNIQUE
Syntax
UPDATE libref.descriptor-name. ACCESS | VIEW ;
244 Chapter 18 • The ACCESS Procedure for PC Files
Details
Overview
Use the UPDATE statement to perform a quick, simple update of a descriptor. For
example, if the PC database file for an existing access descriptor is relocated, you can
use UPDATE with the PATH option to specify the new location.
Descriptors modified by UPDATE are not checked for errors. Where validation is
crucial, use CREATE to overwrite a descriptor rather than UPDATE. The descriptor is a
name in three parts separated by periods (.) .
libref
identifies the library container, which is a location either on the local system's disk or
that the local system can directly access. The libref must have been created
previously by a LIBNAME statement.
descriptor-name
specifies the descriptor that you are updating, which already exists in libref.
ACCESS
indicates that you are updating an access descriptor while VIEW indicates you are
updating a view descriptor.
Multiple UPDATE statements can appear in one ACCESS procedure block. If you use
UPDATE to change an access descriptor, one or more UPDATE statements might be
required for views that depend on the modified access descriptor. You can use UPDATE
and CREATE in the same PROC ACCESS block.
2. These editing statements are not allowed: ASSIGN, DROP, RESET, SELECT, and
UNIQUE.
Examples
view descriptor protects PC file data protects PC file data protects descriptor
from being read or from being updated from being read or
updated updated
In this example, the DATASETS procedure statement assigns the passwords MYPW and
MYDEPT with READ and ALTER levels of protection to the view descriptor
VLib.JobC204:
PROC DATASETS LIBRARY=vlib MEMTYPE=VIEW;
MODIFY jobc204 (READ=mypw ALTER=mydept);
RUN;
For detailed information about the levels of protection and the types of passwords that
you can use, refer to your Base SAS software documentation.
General Guidelines
When you create and use view descriptors, follow these guidelines to minimize the use
of SAS resources and to reduce the time it takes to access data:
• Select only the columns your SAS program needs. Selecting unnecessary columns
adds extra processing time.
• Where possible, specify selection criteria to subset the number of observations
processed by SAS.
• To present PC files data in sorted order, reference a view descriptor in a PROC SQL
query. Otherwise, you might need to extract the data to sort it.
Performance and Efficient View Descriptors for PC Files 247
Chapter 19
The DBLOAD Procedure
Statement Task
LIST Statement List information about SAS variables to be loaded into new file
LOAD Statement Create a file and transfer data to it from an input SAS data set
PATH Statement Indicate the path and name of the PC file that you create and load
RENAME Statement Rename the PC File columns associated with the listed SAS variables
RESET Statement Reset column names, data types, and enable setting of null values
Syntax
PROC DBLOAD DATA=input data DBMS=pc-file-format;
Required Arguments
DATA= INPUT DATA
specifies the input data. The input data can be retrieved from a SAS data set, an SQL
view, a DATA step view, a SAS/ACCESS view descriptor, or and Microsoft Excel
file
Default: the last SAS data set that was created.
Restriction: If the data set is permanent, specify its two-level name libref.SAS data-
set.
DBMS= PC-FILE-FORMAT
specifies the PC file format that you want to access.
252 Chapter 19 • The DBLOAD Procedure
ACCDESC Statement
Creates an access descriptor based on the PC file that you are creating and loading.
Alias: ACCESS
AD
Syntax
ACCDESC=<libref>.access-descriptor;
Details
After the PC file is created and loaded, the access descriptor is automatically created.
You must specify an access descriptor that does not already exist.
An editing statement, such as ACCDESC, must be specified after the database
description statements when you create and load a file.
DELETE Statement
Prevents variables from being loaded into the new PC file.
Restriction: An editing statement, such as DELETE, must be specified after the database-
description statements when you create and load a file.
Interaction: RENAME, RESET
FMTLIB Statement 253
Syntax
DELETE variable-identifier-1<...variable-identifier-n>;
Details
The DELETE statement deletes the specified SAS variables from the PC file being
created. The variable-identifier can be either the SAS variable name or the positional
equivalent from a LIST statement. The positional equivalent is the number that
represents the variable's place in the data set.
For example, if you want to delete the third variable, submit this statement: DELETE 3;
You can delete as many variables as you want in one DELETE statement. If you delete
more than one variable, separate the identifiers with spaces, not commas.
If you delete a variable from the list of variables, the positional equivalents of the
variables do not change. For example, if you delete the second variable, the third
variable is still referenced by the number 3, not 2.
Example
The DELETE statement deletes the third variable. The RENAME statement, includes the
third variable, assigns the default type, and assigns EMPNAME as the name. The
RENAME statement enables you to include variables that you have previously deleted.
DELETE 3; RENAME 3='empname';
ERRLIMIT Statement
Stops loading observations after the specified number of errors has occurred while inserting rows into a
file.
Default: 100
Restrictions: ERRLIMIT must be a nonnegative integer.
An editing statement, such as ERRLIMIT must be specified after the database-
description statements when you create and load a file.
Notes: Applies to DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats
under Microsoft Windows operating environments
Specify ERRLIMIT = 0 to allow an unlimited number of errors to occur.
Syntax
ERRLIMIT=error-limit;
FMTLIB Statement
Specifies the name of a format library to search.
Syntax
FMTLIB=<libref.> member;
254 Chapter 19 • The DBLOAD Procedure
LABEL Statement
Causes DBMS column names to default to SAS labels.
Default: SAS labels.
Restrictions: For the LABEL statement to take effect, the RESET statement must be used after
the LABEL statement.
An editing statement, such as LABEL, must be specified after the database-
description statements when you create and load PC files.
Interaction: RENAME, RESET
Syntax
LABEL;
Details
The LABEL statement causes the column names to default to the SAS variable labels
when the new table is created. If a SAS variable has no label, the variable name is used.
If the label is too long to be a valid column name, the label is truncated.
LIMIT Statement
Limits the number of observations that can be loaded into the new file.
Default: 5000
Restrictions: The load-limit must be a nonnegative integer.
If you omit the LIMIT statement, a maximum of 5,000 observations are inserted.
Note: To load all observations from your input data set, specify LIMIT=0.
Syntax
LIMIT=load-limit;
Details
The LIMIT= statement places a limit on the number of observations that can be loaded
into the new DBMS table. The load-limit argument must be a nonnegative integer. To
load all observations from your input data set, specify LIMIT=0.
The maximum number for the limit statement varies with each PC file.
LIST Statement
Lists information about SAS data sets.
Default: ALL
LOAD Statement 255
Syntax
LIST ALL | COLUMNS | FIELDS | variable-identifier;
Required Arguments
ALL
lists information about all variables in the input SAS data set, regardless of whether
those variables are selected for the load.
COLUMNS
lists information only about the input SAS variables that are selected for loading.
This argument does not apply to DBF files.
FIELDS
lists information only about the input SAS variables that are selected for the load.
variable-identifier
lists information only about the specified variable. The variable-identifier can be
either the SAS variable name or the positional equivalent. The positional equivalent
is the number that represents the variable's position in the data set.
Example
The LIST statement lists information for the column associated with the third SAS
variable
LIST 3;
LOAD Statement
Create a file and transfer data to it from the input data set after the DBLOAD procedure is submitted.
Syntax
LOAD;
Details
This statement causes the interface view engine to create a file and transfer data to it
from the input data set, after the DBLOAD procedure is submitted. This statement is
required to create and load a new file.
When you create and load a file, you must place statements or groups of statements in a
certain order after the PROC DBLOAD statement and its options, as follows:
• Database-description statements: PATH and your PC file specific statements.
• Editing statements: ACCDESC, DELETE, ERRLIMIT, LABEL, LIMIT , LIST,
RENAME, RESET, and WHERE. The order within this group usually does not
matter.
See the individual statements for more information. QUIT is also an editing
statement but using it immediately terminates PROC DBLOAD.
• When creating and loading statement, LOAD must appear last before RUN in order
to create and load the new table.
256 Chapter 19 • The DBLOAD Procedure
PATH Statement
Indicates the path and name of the PC file to create and load.
Restriction: A file with the same name must not already exist. If one does exist, it is not
overwritten. An error message is written to the SAS log, and the PC file that is
specified in this statement is not loaded.
Requirement: This statement is required.
Note: The length of the filename can vary with the operating environment.
See: SAS documentation for your operating environment for any restrictions.
Syntax
PATH='path and filename.PC file-extension' | 'filename' | fileref;
Required Arguments
path and filename.pc-file-extension
specifies the fully qualified path and filename. Enclose the entire path and filename
in quotation marks, including the appropriate PC file extension. If you omit the file
extension, SAS/ACCESS supplies it for you.
filename
specifies the name of a file. The file must be located in your current (default)
directory. If no extension is specified, the SAS/ACCESS interface supplies it for
you. If the filename includes characters that are invalid in a SAS name, or if it begins
with a number, enclose the filename in quotation marks
fileref
specifies a fileref that references the path and name of the file.
QUIT Statement
Exits the procedure without further processing.
Alias: EXIT
Syntax
QUIT;
RENAME Statement
Renames PC file columns that are associated with the listed SAS variables.
Alias: COLUMN
RESET Statement 257
Restriction: An editing statement, such as RENAME, must be specified after the database-
description statements when you create and load a PC file.
Interaction: DELETE, LABEL, RESET
Note: If you omit RENAME, column names default to the corresponding SAS variable
names, unless you specify a LABEL statement.
Syntax
RENAME variable-identifier-1=column-name-1 <...variable-identifier-n=column-name-n>;
Details
The column-name must be a valid PC file column name. If the column name includes
lowercase characters, special characters, or national characters, you must enclose the
column name in quotation marks.
The variable-identifier can be a SAS variable name or the positional equivalent from the
LIST statement. The positional equivalent is the number that represents where to place
the variable in the data set.
You can rename as many variables as you want in one RENAME statement. The
RENAME statement overrides the LABEL statement for columns that are renamed.
Example
The RENAME statement renames the column associated with the third SAS variable.
RENAME 3="employname";
RESET Statement
Resets column names and data types, and the ability to accept null values to their default values.
Restriction: You must use the RESET statement after the LABEL statement for the LABEL
statement to take effect.
Interaction: DELETE, LABEL, RENAME
Note: You can reset as many columns as you want in one RESET statement.
Syntax
RESET ALL | variable-identifier-1<...variable-identifier-n>;
Details
If you specify ALL, all columns are reset to their default values. In addition, any deleted
columns are restored with their default values. An editing statement, such as RESET,
must be specified after the database-description statements when you create and load a
PC file.
The variable-identifier argument can be either the SAS variable name or the positional
equivalent from the LIST statement. The positional equivalent is the number that
represents the variable's place in the data set.
258 Chapter 19 • The DBLOAD Procedure
Example
The RESET statement resets the column associated with the third SAS variable
RESET 3;
WHERE Statement
Loads a subset of observations into the PC file.
Restriction: An editing statement, such as WHERE, must be specified after the database-
description statements when you create and load a PC File.
See: SAS Statements: Reference
Syntax
WHERE SAS-where-expression;
Details
The SAS where-expression must be a valid statement that uses SAS variable names (not
column names) as defined in the input data set.
Example
The WHERE statement loads only the observations where the SAS variable Country has
the value Brazil.
WHERE country='Brazil';
259
Chapter 20
File-Specific Reference for the
ACCESS and DBLOAD
Procedures
Access Descriptors
To create an access descriptor, use the ACCESS procedure with the DBMS=XLS option.
There are six database-description statements:
• GETNAMES
• PATH
• RANGE
• SCANTYPE
• SKIPROWS
• WORKSHEET
These database-description statements supply XLS-specific information to SAS. The
statements must immediately follow the CREATE statement. In addition to the database-
description statements, editing statements can follow the database-description
statements. In addition to the database-description statements, editing statements can
follow the database-description statements.
Database-description statements are required only when you create access descriptors.
Because the XLS information is stored in an access descriptor, you do not repeat the
information when you create view descriptors.
Arguments
Use the Access procedure to define descriptors that identify spreadsheet data and the
conversions necessary to use that data in SAS programs. The Microsoft Excel label data
type is formatted as a SAS character type. The Microsoft Excel number data type is
formatted as a SAS numeric type.
Fonts, attributes, and colors in the XLS files are not read into SAS data sets. The Access
procedure supports most of the XLS number formats and automatically converts them to
the corresponding SAS formats. XLS data strings that are longer than 200 characters are
ACCESS Procedure: XLS Files 261
truncated during conversion to SAS data sets. XLS files that create SAS data sets can
contain up to 256 variables and 16,384 observations.
w is based on Excel column width. The Excel format string controls .d.
If XLS files data falls outside of the valid SAS data ranges, you receive an error message
in the SAS log when you try to access the data.
The SAS/ACCESS interface does not fully support the Microsoft Excel hidden and text
formats. XLS data in hidden format is displayed in SAS data sets. You can drop the
hidden column when you are creating the access descriptor. To display a formula in text
format, add a space to indicate that the formula entry is a label. Otherwise, the results of
the formula display.
You can change the default value from NO to YES by setting the SS_MIXED
environment variable.
See “Setting Environment Variables for XLS Files” on page 270.
Set the SS_MIXED environment variable to YES and numeric values in XLS files are
converted to character strings if the corresponding SAS variable type is character.
Syntax
PROC ACCESS DBMS= XLS | EXCEL;
CREATE libref.member-name. ACCESS | VIEW;
GETNAMES= YES | NO | Y | N;
PATH='path-and-filename' .XLS ' | 'filename' '| fileref;
RANGE= <'range-name'> | <'range-address'>;
SCANTYPE= YES | NO | Y | N | <number-of-rows>;
UPDATE libref.member-name.ACCESS | VIEW;
ASSIGN=YES | NO | Y | N;
DROP= <'column-identifier-1'> …<'column-identifier-n'>;
FORMAT=<'column-identifier-1'>=<'SAS format-name-1'>…<'column-identifier-n'>=
<'SAS format-name-n'>
LIST= ALL | VIEW | <column-identifier>
MIXED = YES | NO | Y | N
RENAME=<'column-identifier-1''SAS variable-name-1'>…<'column-identifier-n'>
<'SAS variable-name-n'>
RESET ALL | <'column-identifier-1'> ,...<'column-identifier-n'>
SELECT ALL | <'column-identifier-1'> ,…<'column-identifier-n'>
SKIPROWS= <number-of-rows-to-skip>
SUBSET <selection-criteria>
TYPE 'column-identifier-1'. C | N <'column-identifier-n'>,C | N
UNIQUE=YES | NO | Y | N
WORKSHEET=<'worksheet-name'> RUN;
262 Chapter 20 • File-Specific Reference for the ACCESS and DBLOAD Procedures
1 Label data.
2 The XLS character format for Excel Version 5.
3 Number, formula, or missing data.
ACCESS Procedure: XLS Files 263
Table 20.2 SAS Variable Formats for Customized XLS Format Strings
Value Description
Num W 0 NUMBER
Excel column widths are set to w and display in the column. If the data is larger than
column width, it displays as pound signs (###). In that case, you can view it by adjusting
the column width.
You can change the default behavior of the ACCESS procedure and the DBLOAD
procedure by setting environment variables in your SAS configuration file. You can set
three SAS/ACCESS environment variables: SS_MIXED, SS_NAMES, and SS_SCAN.
Setting these variables in your SAS configuration file defines how the interface works.
The configuration file omits these three environment variables. Their default values are
NO.
SS_MIXED =YES|NO
YES allows both Microsoft Excel numeric and character data in a column to be
displayed as SAS character data. The Microsoft Excel numeric data is converted to
its character representation when its corresponding SAS variable type is defined as
character.
NO does not convert Microsoft Excel numeric data in a column into SAS character
data. Microsoft Excel numeric data is read in as SAS missing values when its
corresponding SAS variable type is defined as character. NO is the default.
Setting the SS_MIXED environment variable changes the default value of the
MIXED statement in the Access procedure.
SS_NAMES= YES|NO
YES allows the Access procedure to generates SAS variable names from column
names. The first row of the worksheet or the specified range of the worksheet is used
to generate SAS variable names. Data is then read from the second row.
YES in the DBLOAD procedure writes column names using SAS variable names.
YES also writes SAS variable labels to the first row of the XLS file. SAS reads the
data from the data set, and writes it to the XLS file beginning with the second row.
NO in the Access procedure generates the SAS variable names VAR0, VAR1,
VAR2, and so on, and reads data from the first row of the worksheet or specified
range.
NO in the DBLOAD procedure reads the data from the data set and writes it to the
XLS file beginning with the first row. NO is the default.
Setting the SS_NAMES environment variable changes the default value of the
GETNAMES= option in the Access procedure and the PUTNAMES= option in the
DBLOAD procedure.
SS_SCAN= YES | NO | number-of-rows
YES scans the data type and format of rows in a worksheet or specified range after
skipping the number of rows specified in the SKIPROWS statement. After scanning
the rows, SS_SCAN finds the most common Microsoft Excel data type and format in
ACCESS Procedure: WKn Specifics 271
order to generate the default SAS data type and format. If a number of rows is
specified, SAS/ACCESS scans the data type and format only from these rows.
NO uses the type and format of the first row in a worksheet or specified range. If
SKIPROWS= is specified, the first row is after skipping the number of rows
specified. NO is the default.
Number-of-rows scans only the type and format of the specified number of rows.
Setting the number of rows is more efficient because data is read from only the
specified number of rows rather than the entire file.
Setting the SS_SCAN environment variable changes the default value of the
SCANTYPE statement in the Access procedure.
The RANGE statement is optional. Omit RANGE and the entire worksheet is
accessed as the default range.
The RANGE is a database-description statement. It must follow the CREATE
statement and precede any editing statements when you create a descriptor.
SCANTYPE= YES | NO | Y | N | number-of-rows
finds the most common Lotus 1-2-3 format for each column in a specified number of
rows in a WKn worksheet to generate the SAS format. SAS variable formats are
generated from the Lotus 1-2-3 formats found in the first row of the worksheet or in
the specified range of the worksheet.
The SCANTYPE statement is optional, and its default value is NO. Specify YES and
the ACCESS procedure scans the Lotus 1-2-3 formats of all the rows in each column
of the range. The procedure uses the most common format to generate the default
SAS format for each column. Specify a number of rows for the Access procedure to
scan only the specified number of rows. The procedure returns the most common
format.
Specify the SKIPROWS statement and the ACCESS procedure skips the specified
rows. It starts scanning the Lotus 1-2-3 format from the next row. Specify
SKIPROWS=3 and the Access procedure begins scanning the formats on the fourth
row.
You can change the default value to YES by setting the SS_SCAN environment
variable. For more information, see “Setting Environment Variables for WKn Files”
on page 277.
Specifying SCANTYPE=0 is equivalent to specifying SCANTYPE=NO.
The SCANTYPE statement is a database-description statement. It must follow the
CREATE statement and precede any editing statements when you create a
descriptor.
SKIPROWS = number-of-rows-to-skip
specifies the number of rows, beginning at the top of the range in the WKn file, to
ignore when you are reading data from the WKn file. The default value for
SKIPROWS is 0. The skipped (or ignored) rows often contain information such as
column labels or names, or underscores rather than input data.
If GETNAMES=YES, the default value of SKIPROWS= automatically changes to 1.
The first row of data and formats after SKIPROWS in a range are used to generate
the SAS variable types and formats. You can use the SCANTYPE= statement to scan
the formats of specified rows. Then use the most common type and format to
generate the SAS variable types and formats.
The SKIPROWS= statement is a database-description statement. It must follow the
CREATE statement and precede any editing statements when you create a
descriptor. The CREATE= option precedes the SKIPROWS= option. Editing
statements follow the SKIPROWS= option.
WORKSHEET= worksheet-letter | worksheet-name
identifies a particular worksheet when you are reading from a WKn file that contains
more than one worksheet. You can specify a worksheet name or a worksheet letter
using the WORKSHEET statement. Worksheet names can be up to 15 characters
long and are not case sensitive. A worksheet letter is a one- or two-letter alpha
character. For WK1 files, there is only one worksheet letter: worksheet A. For WK3
and WK4 files, there can be up to 256 different worksheet letters: worksheet A
through worksheet Z and worksheet AA through worksheet IV. The default value is
A. Specifying WORKSHEET=B identifies worksheet B from a group of worksheets.
274 Chapter 20 • File-Specific Reference for the ACCESS and DBLOAD Procedures
Table 20.5 Default SAS System Variable Formats for WKn File Data
Column Decimal
Data Type Data Format Width Number Type Format
Column Decimal
Data Type Data Format Width Number Type Format
Column
Type Data Format Data Type Column Format Width Number
The configuration file omits these three environment variables, which means their
default values are NO.
SS_MISS NULLS
The DBLOAD procedure loads Lotus @NA cell values for missing values. Use this
option to specify a null cell value instead. If set, missing values in a SAS data set
are displayed as blanks in the Lotus 1-2-3 table.
SS_MIXED= YES | NO
YES allows both Lotus 1-2-3 numeric and character data in a column to be displayed
as SAS character data. The Lotus 1-2-3 numeric data is converted to its character
representation when its corresponding SAS variable type is defined as character.
NO does not convert Lotus 1-2-3 numeric data in a column into SAS character data.
Lotus 1-2-3 numeric data is read in as SAS missing values when its corresponding
SAS variable type is defined as character. NO is the default.
Setting the SS_MIXED environment variable changes the default value of the
MIXED statement in the Access procedure.
SS_NAMES YES | NO
YES in the Access procedure generates SAS variable names from column names in
the first row of the worksheet or specified range of the worksheet. Data is then read
starting from the second row.
YES in the DBLOAD procedure writes column names using SAS variable names or
SAS variable labels to the first row of the new WKn file. Data is then read from the
data set and written to the WKn file beginning with the second row.
NO in the Access procedure generates the SAS variable names VAR0, VAR1,
VAR2, and so on. It reads data from the first row of the worksheet or a specified
range. NO is the default.
NO in the DBLOAD procedure reads the data from the data set and writes it to the
WKn file beginning with the first row.
Setting the SS_NAMES environment variable changes the default value of the
GETNAMES= option in the Access procedure, and the PUTNAMES= option in the
DBLOAD procedure.
SS_SCAN= YES | NO |number-of-rows
YES scans the data type and format of rows in a worksheet or specified range. If
SKIPROWS= is specified, the first row is after skipping the number of rows
specified. SS_SCAN finds the most common Lotus 1-2-3 data type and format to
generate the SAS data type and format. If a number of rows is specified, the Access
procedure scans only the data type and format from the specified rows.
NO uses the type and format of the first row in a worksheet or specified range. If
SKIPROWS= is specified, the first row is after skipping the number of rows
specified. NO is the default.
Number-of-rows scans only the type and format of the specified number of rows.
Setting the number of rows is more efficient because data is read from only the
specified number of rows rather than the entire file.
Setting the SS_SCAN environment variable changes the default value of the
SCANTYPE= statement option in the Access procedure.
ACCESS Procedure: DBF Specifics 279
Table 20.7 Default SAS Variable Formats for DBF File Data Types
Numeric(N,n) (N,n)
Float(N,n)* (N,n)
Date MMDDYY8.
Logical $1.
* This data type applies to dBASE V and later. Check with other software products' documentation to
determine whether this data type applies.
This example creates a DBF table, Exchange.Dbf, from the data file DLib.RateOfex. An
access descriptor DbFliba.Exchange is created based on the new table. You must be
granted the appropriate privileges to create DBF tables.
LIBNAME dbfliba 'SAS data-library';
LIBNAME dlib 'SAS data-library';
Table 20.8 DBF File Data Types Assign Corresponding SAS Variable Formats
$w. CHAR(n)
w. NUMERIC
w.d. NUMERIC
datetimew.d DATE
datew. DATE
ew. FLOAT
binaryw. NUMERIC
DIFLABEL
indicates whether variable names are generated from the first row of the columns.
Omit this statement and variable names are generated based on the columns'
placement in the first row. SAS labels each column as COL0, COL1, COL2, and so
on. These labels are the names of SAS variables in the access descriptor.
Specify DIFLABEL and the ACCESS procedure reads column labels from the first
row of the DIF file. The labels are also used as the SAS variable names in the access
descriptor. You provide the DIF file column labels; they are not the letters ( A, B,
and so on) that identify the columns in a worksheet. Specify DIFLABEL , and the
SKIPROWS= statement automatically changes to 1.
Always specify the DIFLABEL statement after the PATH= statement and before any
editing statements. When you update a descriptor, the DIFLABEL statement cannot
be changed.
Create an Access Descriptor and a View Descriptor Based on DIF file data.
OPTIONS LINESIZE=80;
LIBNAME difliba ’SAS data-library’;
LIBNAME diflibv ’SAS data-library’;
SKIPROWS =number-of-rows-to-skip;
specifies the number of rows, beginning at the top of the DIF file, to skip when
reading data. The default value for SKIPROWS is 0. The skipped rows often contain
information such as column labels or names, or underscores rather than input data.
When you specify the DIFLABEL statement, the default value of SKIPROWS
automatically changes to 1.
When you are creating a description, SKIPROWS= should always follow the
PATH= statement and precede any editing statements. The first row of data after
SKIPROWS= is used to generate the SAS variable types and formats. If there is no
data in the first row of a column after SKIPROWS, the data in the rest of the column
is assumed to be character. This is true even if the data in the next row is numeric.
Any data value in a column that does not match the type is treated as a missing
value.
If you set the DIFNUMS environment variable to YES in your SAS configuration
file, numeric values in a character column are converted to character. The values are
not treated as missing values. To set the DIFNUMS value, add the following line to
your SAS configuration file: -SET DIFNUMS YES
The default value for the DIFNUMS environment variable is NO.
ACCESS Procedure: DIF Specifics 285
You can change the column type from the default type that the Access procedure
defines when you create an access descriptor.
Note: Refer to the SAS documentation for your operating environment for more
information about environment variables.
Table 20.9 Default SAS Variable Formats for DIF File Data
C (Character) $20.
N (Numeric) 15.2
If DIF file data falls outside of the valid SAS data ranges, you get an error message in
the SAS log when you try to read the data.
The QUIT statement is also available in the DBLOAD procedure. It causes the
procedure to terminate. QUIT is used most often in interactive line mode and batch
mode to exit the procedure without exiting SAS.
The following list provides detailed information about the DIF-specific statements:
DIFLABEL
writes column labels to the first row of the new DIF file and follows the column
labels with a blank row. The column labels can be default SAS variable names.
Specify the LABEL statement to use SAS labels. You can modify the column labels
using the RENAME statement.
Note: If this statement is omitted, data is read from the data set and written to the
DIF file beginning in the first row. No column labels are written to the file.
FORMAT SAS variable-name-1SAS format-1…SAS variable-name-nSAS format-n
assigns a temporary SAS format to a SAS variable in the input SAS data set. This
format temporarily overrides any other format for the variable. The assignment lasts
for the duration of the procedure. You can assign formats to as many variables as
you want in one FORMAT statement.
Use the FORMAT statement to change the format, column width, or the number of
decimal digits for columns being loaded into the PC file. If you change the SAS
variable format 12.1 to DOLLAR15.2, the column format of the loaded data
DBLOAD Procedure: DIF Specifics 287
changes. The fixed numeric format with a column width of 12 and one decimal digit
changes to a currency format with a column width of 15 and two decimal digits.
This example creates a DIF table, Exchange.dif, from the data file Dlib.RateOfex. An
access descriptor AdLib.Exchange is also created based on the new DIF table. You must
be granted the appropriate privileges in order to create new DIF files.
LIBNAME dlib 'SAS data-library';
LIBNAME adlib 'SAS data-library';
The default for the DIFNUMS environment variable is NO. Refer to the SAS
Companion for your operating system for more information about environment
variables.
You can change the column type from the type that SAS/ACCESS determines when you
create an access descriptor.
289
Part 6
Appendixes
Appendix 1
LIBNAME Statement for the JMP Engine . . . . . . . . . . . . . . . . . . . . . . . . 291
Appendix 2
The DBF and DIF Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
290
291
Appendix 1
LIBNAME Statement for the JMP
Engine
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
LIBNAME Statement for the JMP Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Dictionary
Syntax
LIBNAME libref JMP ‘path’ <FMTLIB=libref.format-catalog>;
Arguments
libref
is a character constant, variable, or expression that specifies the libref that is assigned
to a SAS library.
Range: 1 to 8 bytes
path
is the physical name for the SAS library. The physical name is the name that is
recognized by the operating environment. Enclose the physical name in single or
double quotation marks.
FMTLIB=libref.format-catalog
specifies where the formats are stored when a JMP data table is read and where the
formats come from when a JMP data table is created.
Requirement: The library that is specified in the FMTLIB argument must be a SAS
data set LIBNAME statement.
Example:
292 Appendix 1 • LIBNAME Statement for the JMP Engine
Details
A JMP file is a file format that the JMP software program creates. JMP is an interactive
statistics package that is available for Microsoft Windows and Macintosh. For more
information, see the JMP documentation that is packaged with your system.
A JMP file contains data that is organized in a tabular format of fields and records. Each
field can contain one type of data, and each record can hold one data value for each field.
Base SAS supports access to JMP files. You can access JMP files by either of these two
methods:
• the IMPORT and EXPORT procedures and the Import and Export Wizard without a
license for SAS/ACCESS Interface to PC Files
For more information, see SAS/ACCESS Interface to PC Files: Reference.
• the LIBNAME statement for the JMP engine
Examples
Appendix 2
The DBF and DIF Procedures
Dictionary
Syntax
PROC DBF option(s)
Required Argument
DB2 | DB3 | DB4 | DB5 =fileref |filename
specifies the version of the dBase file and the fileref or filename of a DBF file. The
DB n option must correspond to the version of dBASE with which the DBF file is
compatible. Specify the version with the DB n option, where n is the version number.
The values are 2, 3, 4, or 5.
294 Appendix 2 • The DBF and DIF Procedures
To specify a fileref, the FILENAME statement must specify the filename with a .dbf
extension. This example assigns the fileref myref to the file '/my_dir/myfile.dbf':
filename myref '/my_dir/myfile.dbf';
If you specify a filename instead of a fileref, specify the filename without the .dbf
extension. The file must be in the current directory, in uppercase.
The following PROC DBF statement creates the EMP.DBF file (with the name in
uppercase) from the MyLib.Employee data set:
PROC DBF DB5=emp DATA=mylib.employee;
Restriction: You cannot specify the filename extension .dbf or a full pathname.
PROC DBF DB5='/my/unix_directory/emp.dbf'.
Requirements:
You must specify a FILENAME statement.
The DB n = option is required.
Optional Arguments
DATA= <libref>.member
specifies the name of the SAS data set you are reading to create a DBF file. If you
omit the DATA= option, SAS creates an output SAS data set from the DBF file. The
output file is written to the temporary WORK directory. The naming convention is
Data1, Data2, DataN. The temporary WORK file is available only during your
current SAS session.
OUT=<libref.>member
specifies the name of the SAS data set you are creating from a DBF file. If you omit
the OUT= option, SAS creates an output SAS data set from the DBF file. Use this
option only if you are creating a SAS data set from a DBF file and you did not
specify the DATA= option.
If OUT= is omitted, SAS creates a temporary data set in the Work library. (Under
UNIX, the temporary data set is named Data1, ..., Data n]. Under Microsoft
Windows, it is called _DATA_). The WORK data set remains available only during
your current SAS session.
Details
Overview
The DBF procedure converts data interchange format (DBF) files to SAS data sets. The
data sets are compatible with the current release of SAS software, or SAS data sets
convert to DBF files.
PROC DBF produces one output file but no printed output. The output file contains the
same information as the input file but in a different format.
Software Arts, Inc. developed the data interchange format to be used as a common
language for data. Originally, DBF was made popular by products such as Lotus 1-2-3
and VisiCalc. Although DBF is not as popular today, it is still supported by many
software products.
When you are converting a DBF file, each row of the file becomes an observation in the
SAS data set. Conversely, when you are converting a SAS data set, each SAS
observation becomes a row in the DBF file. To use the DBF procedure, you must have a
SAS/ACCESS Interface to PC Files license.
The DBF Procedure 295
Note: Any DBF file that you plan to import to a SAS data set should be in a tabular
format. All items in a given column should represent the same type of data. If the
DBF file contains inconsistent data, such as a row of underscores, hyphens, or
blanks, delete these rows before converting the file. It is recommended that you
make a backup copy of your DBF table before you make these modifications.
Examples
Syntax
PROC DIF option(s);
PROC Statement
DIF = fileref | filename
Statement Option
DATA= libref.member
LABELS
OUT=
PREFIX= name
SKIP= n
Optional Arguments
DIF = fileref | filename
specifies the fileref or filename of a DIF file.
If you specify a fileref, the FILENAME statement that you used to define it must
specify the filename plus a .dif extension.
filename myref '/my_dir/myfile.dif'
If you specify a filename instead of a fileref, you can specify only the name itself
(omitting the .dif extension) and the file must be in the current directory. This PROC
DIF statement creates the Emp.dif file from the MyLib.Employee data set:
PROC DIF dif=emp data=mylib.employee;
RUN:
DATA= libref.member
names the input SAS data set. Use this option if you are creating a DIF file from a
SAS data set. If you use this option, do not use the OUT= option. If you omit the
DATA= option, SAS creates an output SAS data set from the DIF file.
OUT=
names the SAS data set to hold the converted data. You use this option only if you
omit the DATA= option and you are creating a SAS data set from a DIF file.
If OUT= is omitted, SAS creates a temporary data set in the Work library. (Under
UNIX, the temporary data set is named Data1, ..., DataN). Under Microsoft
298 Appendix 2 • The DBF and DIF Procedures
Details
Overview
The DIF procedure converts data interchange format (DIF) files to SAS data sets. The
data sets are compatible with the current release of SAS software, or SAS data sets
convert to DIF files.
PROC DIF produces one output file but no printed output. The output file contains the
same information as the input file but in a different format.
Software Arts, Inc. developed the data interchange format to be used as a common
language for data. Originally, DIF was made popular by products such as Lotus 1-2-3
and VisiCalc. Although DIF is not as popular today, it is still supported by many
software products.
Note: Any DIF file that you plan to import to a SAS data set should be in a tabular
format. All items in a given column should represent the same type of data. If the
DIF file contains inconsistent data, such as a row of underscores, hyphens, or blanks,
delete these rows before converting the file. It is recommended that you make a
backup copy of your DIF table before you make these modifications.
When you are converting a DIF file, each row of the file becomes an observation in the
SAS data set. Conversely, when you are converting a SAS data set, each SAS
observation becomes a row in the DIF file.
To use the DIF procedure, you must have a SAS/ACCESS Interface to PC Files license.
marks that normally enclose character variable values in a DIF file are removed when
the value is converted to a SAS character value.
Numeric variables represented as integers or scientific notation in a DIF file, become
SAS numeric variables when converted to a SAS data set.
Missing Values
The developers of the data interchange format (DIF) files suggest that you treat all
numeric values with a value indicator other than V as missing values. The DIF procedure
follows this convention. When a DIF file is imported to a SAS data set, any numeric
value with a value indicator other than V becomes a SAS missing value.
When a SAS data set with missing numeric values is converted to a DIF file, the
following assignments are made in the DIF file for the variables with missing values:
• the type indicator field value is set to 0
• the number field value contains a string of 16 blanks
• the value indicator is set to NA.
Examples
Glossary
access descriptor
a SAS/ACCESS file that describes data that is managed by SAS, by a database
management system, or by a PC-based software application such as Microsoft Excel,
Lotus 1-2-3, or dBASE. After creating an access descriptor, you can use it as the
basis for creating one or more view descriptors.
client
an application that requests either resources or services from a server, possibly over a
network.
column
a vertical component of a table. Each column has a unique name, contains data of a
specific type, and has particular attributes. A column is analogous to a variable in
SAS terminology.
commit
the process that ends a transaction and that makes permanent any changes to the
database that the user made during the transaction.
data set
See SAS data set.
data type
an attribute of every column in a table or database. The data type tells the operating
system how much physical storage to set aside for the column and specifies what
302 Glossary
type of data the column will contain. It is similar to the type attribute of SAS
variables.
data value
a unit of character, numeric, or alphanumeric information. This unit is stored as one
item in a data record, such as a person’s height being stored as one variable (namely,
a column or vertical component) in an observation (row).
data view
See SAS data view.
database
an organized collection of related data. A database usually contains named files,
named objects, or other named entities such as tables, views, and indexes.
database field
a vertical component of a dBASE .DBF file that contains data of a specific type with
certain attributes. A database field is analogous to a variable in SAS terminology.
DBMS
See database management system.
delimiter
a character that serves as a boundary that separates the elements of a text string.
DIF file
See Data Interchange Format file.
engine
a component of SAS software that reads from or writes to a file. Various engines
enable SAS to access different types of file formats.
format
See SAS format.
index
a component of a SAS data set that enables SAS to access observations in the SAS
data set quickly and efficiently. The purpose of SAS indexes is to optimize WHERE-
clause processing and to facilitate BY-group processing.
library reference
See libref.
Glossary 303
libref
a SAS name that is associated with the location of a SAS library. For example, in the
name MYLIB.MYFILE, MYLIB is the libref, and MYFILE is a file in the SAS
library.
member
an element of a dimension. For example, for a dimension that contains time periods,
each time period is a member of the dimension.
member name
a name that is assigned to a SAS file in a SAS library.
member type
a SAS name that identifies the type of information that is stored in a SAS file.
Member types include ACCESS, AUDIT, DMBD, DATA, CATALOG, FDB,
INDEX, ITEMSTOR, MDDB, PROGRAM, UTILITY, and VIEW.
missing value
a type of value for a variable that contains no data for a particular row or column. By
default, SAS writes a missing numeric value as a single period and a missing
character value as a blank space.
observation
a row in a SAS data set. All of the data values in an observation are associated with a
single entity such as a customer or a state. Each observation contains either one data
value or a missing-value indicator for each variable.
pass-through facility
See SQL pass-through facility.
PC Files Server
a SAS application that receives client requests to access Microsoft Windows-specific
data files, such as Microsoft Excel and Microsoft Access. The application runs on
both 32-bit and 64-bit Windows, as either a 32-bit or a 64-bit application.
query
a set of instructions that requests particular information from one or more data
sources.
RDBMS
See relational database management system.
record
See data record, schema record.
rollback
a data recovery process that restores a database after a hardware or software failure,
or that returns it to a state before changes were made.
SAS format
a type of SAS language element that applies a pattern to or executes instructions for
a data value to be displayed or written as output. Types of formats correspond to the
data's type: numeric, character, date, time, or timestamp. The ability to create user-
defined formats is also supported. Examples of SAS formats are BINARY and
DATE. Short form: format.
SAS metadata
metadata that is created by SAS software. Metadata that is in SAS Open Metadata
Architecture format is one example.
SAS variable
a column in a SAS data set or in a SAS data view. The data values for each variable
describe a single characteristic for all observations (rows).
server
software that provides either resources or services to requesting clients, possibly over
a network.
SQL
See Structured Query Language.
type
See data type.
variable
See SAS variable.
view
a definition of a virtual data set that is named and stored for later use. A view
contains no data; it merely describes or defines data that is stored elsewhere.
view descriptor
a SAS/ACCESS file that defines part or all of the DBMS data that is described by an
access descriptor.
306 Glossary
307
Index
sorting data 85, 106, 174, 189 Jet and Ace 144
subsetting data 106, 189 QUIT statement
PC Files Server 162 ACCESS procedure 238, 272, 279, 283
access to 168 DBLOAD procedure 256, 276, 281,
administration 168 286
application modes (32-bit versus 64-bit)
163
authentication 167 R
autostart 169 RANGE statement
configuration 166 ACCESS procedure 272
constraints 170 RANGE= option
data encryption 167 statement for Excel 41, 47, 50
desktop application 164 statement for Lotus 1–2–3 64
installation 163 ranges 33
maximum connections 167 importing to data sets 45
operating modes 163 READBUFF= data set option 118, 202
port number 163, 167 READBUFF= LIBNAME option 126,
running as desktop application 164 185
security 167 READBUFF= option
service name 167 CONNECT statement 136, 211
shared information 171 registry editor
user accounts 170 TypeGuessRows 39
Windows service 163 RENAME statement
PCFFSCL.SAS file 262 ACCESS procedure 239
PCFILES DBLOAD procedure 256
queries 219 REPLACE option
performance PROC EXPORT statement 26
joins 109, 193 PROC IMPORT statement 19
platforms, supported 7 RESET statement
port number ACCESS procedure 240
PC Files Server 163, 167 DBLOAD procedure 257
PORT= LIBNAME option 176 return codes
PORT= option Pass-Through Facility, UNIX 206
CONNECT statement 132, 208 rollback, error limit for 115, 198
statement for Access 58 row processing
statement for Excel 41 commit statement for 105, 188
PREFIX= rows
DIF procedure 298 insertion method 116, 199
printing number for single insert 116, 199
SASTRACE information 94 number to read into buffer 118, 202
PROC DBLOAD statement 251
PROC EXPORT statement 22
PROC IMPORT statement 13 S
PROC SQL 129 sample data 4
procedure 226, 297 SASDATEFMT= data set option 119,
PROMPT= argument 202
CONNECT statement 139, 214 SASTRACE= system option 91
PROMPT= LIBNAME option 99 printing trace information 94
PUTNAMES statement SAV data types 75
DLOAD procedure 276 SAV files 75
PUTNAMES= option SCAN_TEXTSIZE= LIBNAME option
statement for Excel 50 185
SCAN_TIMETYPE= LIBNAME option
126, 185
Q SCANMEMO= option
queries 219 statement for Access 58
Index 315