Previous Page | Next Page

SAS/ACCESS Interface to ODBC

LIBNAME Statement Specifics for ODBC


Overview

This section describes the LIBNAME statement that SAS/ACCESS Interface to ODBC supports and includes examples. For details about this feature, see Overview of the LIBNAME Statement for Relational Databases.

Here is the LIBNAME statement syntax for accessing ODBC.

LIBNAME libref odbc <connection-options> <LIBNAME-options>;

Arguments

libref

specifies any SAS name that serves as an alias to associate SAS with a database, schema, server, or group of tables and views.

odbc

specifies the SAS/ACCESS engine name for the ODBC interface.

connection-options

provide connection information and control how SAS manages the timing and concurrence of the connection to the DBMS. When you use the LIBNAME statement, you can connect to ODBC in many different ways. Specify only one of these methods for each connection because they are mutually exclusive.

  • USER=, PASSWORD=, DATASRC=

  • COMPLETE=

  • NOPROMPT=

  • PROMPT=

  • READBUFF=

  • REQUIRED=

Here is how these options are defined.

USER=<'>user-name<'>

lets you connect to an ODBC database with a user ID that is different from the default ID. USER= is optional. UID= is an alias for this option.

PASSWORD=<'>password<'>

specifies the ODBC password that is associated with your user ID. PASSWORD= is optional. PWD is an alias for this option. If you do not want to enter your DB2 password in uncoded text on this statement, see PROC PWENCODE in Base SAS Procedures Guidefor a method to encode it.

DATASRC=<'>ODBC-data-source<'>

specifies the ODBC data source to which you want to connect. For PC platforms, data sources must be configured by using the ODBC icon in the Windows Control Panel. For UNIX platforms, data sources must be configured by modifying the .odbc.ini file. DSN= is an alias for this option that indicates that the connection is attempted using the ODBC SQLConnect API, which requires a data source name. You can also use a user ID and password with DSN=. If you want to use an ODBC file DSN, then instead of supplying DATASRC=<'>ODBC-data-source<'>, use the PROMPT= or NOPROMPT= option followed by "filedsn=(name-of-your-file-dsn);". For example:

libname mydblib odbc noprompt="filedsn=d:\share\msafiledsn.dsn;";
COMPLETE=<'>ODBC-connection-options<'>

specifies connection options for your data source or database. Separate multiple options with a semicolon. When connection succeeds, the complete connection string is returned in the SYSDBMSG macro variable. If you do not specify enough correct connection options, you are prompted with a dialog box that displays the values from the COMPLETE= connection string. You can edit any field before you connect to the data source. This option is not supported on UNIX platforms. See your ODBC driver documentation for more details.

NOPROMPT=<'>ODBC-connection-options<'>

specifies connection options for your data source or database. Separate multiple options with a semicolon. If you do not specify enough correct connection options, an error is returned. No dialog box displays to help you complete the connection string.

PROMPT=<'>ODBC-connection-information<'>

specifies connection options for your data source or database. Separate multiple options with a semicolon. When connection succeeds, the complete connection string is returned in the SYSDBMSG macro variable. PROMPT= does not immediately try to connect to the DBMS. Instead, it displays a dialog box that contains the values that you entered in the PROMPT= connection string. You can edit values or enter additional values in any field before you connect to the data source. This option is not supported on UNIX platforms.

READBUFF= number-of-rows

Use this argument to improve the performance of most queries to ODBC. By setting the value of the READBUFF= argument in your SAS programs, you can find the optimal number of rows for a specified query on a specified table. The default buffer size is one row per fetch. The maximum is 32,767 rows per fetch, although a practical limit for most applications is less and depends upon on the available memory.

REQUIRED=<'>ODBC-connection-options<'>

specifies connection options for your data source or database. Separate multiple options with a semicolon. When connection succeeds, the complete connection string is returned in the SYSDBMSG macro variable. If you do not specify enough correct connection options, a dialog box prompts you for the connection options. REQUIRED= lets you modify only required fields in the dialog box. This option is not supported on UNIX platforms.

See your ODBC driver documentation for a list of the ODBC connection options that your ODBC driver supports.

These ODBC connection options are not supported on UNIX.

  • BULKCOPY=

  • COMPLETE=

  • PROMPT=

  • REQUIRED=

LIBNAME-options

define how SAS processes DBMS objects. Some LIBNAME options can enhance performance, while others determine locking or naming behavior. The following table describes the LIBNAME options for SAS/ACCESS Interface to ODBC, with the applicable default values. For more detail about these options, see LIBNAME Options for Relational Databases.

SAS/ACCESS LIBNAME Options for ODBC
Option Default Value
ACCESS=
none
AUTHDOMAIN=
none
AUTOCOMMIT=
data-source specific
BL_LOG=
none
BL_OPTIONS=
none
BULKLOAD=
NO
CONNECTION=
data-source specific
CONNECTION_GROUP=
none
CURSOR_TYPE=
FORWARD_ONLY
DBCOMMIT=
1000 (inserting) or 0 (updating)
DBCONINIT=
none
DBCONTERM=
none
DBCREATE_TABLE_OPTS=
none
DBGEN_NAME=
DBMS
DBINDEX=
YES
DBLIBINIT=
none
DBLIBTERM=
none
DBMAX_TEXT=
1024
DBMSTEMP=
NO
DBNULLKEYS=
YES
DBPROMPT=
NO
DBSLICEPARM=
THREADED_APPS,2 or 3
DEFER=
NO
DELETE_MULT_ROWS=
NO
DIRECT_EXE=
none
DIRECT_SQL=
YES
IGNORE_ READ_ONLY_COLUMNS=
NO
INSERT_SQL=
data-source specific
INSERTBUFF=
1
KEYSET_SIZE=
0
LOGIN_TIMEOUT
0
MULTI_DATASRC_OPT=
NONE
PRESERVE_COL_NAMES=
see Naming Conventions for ODBC
PRESERVE_TAB_NAMES =
see Naming Conventions for ODBC
QUALIFIER=
none
QUERY_TIMEOUT=
0
QUOTE_CHAR=
none
READ_ISOLATION_LEVEL=
RC (see Locking in the ODBC Interface)
READ_LOCK_TYPE=
ROW
READBUFF=
0
REREAD_EXPOSURE=
NO
SCHEMA=
none
SPOOL=
YES
SQL_FUNCTIONS=
none
SQL_FUNCTIONS_COPY=
none
STRINGDATES=
NO
TRACE=
NO
TRACEFILE=
none
UPDATE_ISOLATION_LEVEL=
RC (see Locking in the ODBC Interface)
UPDATE_LOCK_TYPE=
ROW
UPDATE_MULT_ROWS=
NO
UPDATE_SQL=
driver-specific
USE_ODBC_CL=
NO
UTILCONN_TRANSIENT=
NO


ODBC LIBNAME Statement Examples

In the following example, USER=, PASSWORD=, and DATASRC= are connection options.

libname mydblib odbc user=testuser password=testpass datasrc=mydatasource;

In this example, the libref MYLIB uses the ODBC engine to connect to an Oracle database. The connection options are USER=, PASSWORD=, and DATASRC=.

libname mydblib odbc datasrc=orasrvr1 user=testuser  password=testpass;

proc print data=mydblib.customers;
   where state='CA';
run;

In the next example, the libref MYDBLIB uses the ODBC engine to connect to a Microsoft SQL Server database. The connection option is NOPROMPT=.

libname mydblib odbc
   noprompt="uid=testuser;pwd=testpass;dsn=sqlservr;"
   stringdates=yes;

proc print data=mydblib.customers; 
   where state='CA';
run;

Previous Page | Next Page | Top of Page