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 the LIBNAME statement.
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 it contains spaces or nonalphanumeric characters, you must enclose it in quotation marks. If you do not want to enter your DB2 password in uncoded text on this statement, see PROC PWENCODE in the Base SAS Procedures Guide for 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, 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;";
Alias: DATABASE=, DB=, 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 is displayed 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 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, and 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.

ODBC LIBNAME Statement Examples

In this example, USER=, PASSWORD=, and DATASRC= are connection options.
libname mydblib odbc user=testuser password=testpass datasrc=mydatasource;
In this next 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;