LIBNAME Statement for the DB2 Engine under UNIX and PC Hosts

Overview

This section describes the LIBNAME statement that SAS/ACCESS Interface to DB2 under UNIX and PC Hosts supports.For general information about this feature, see LIBNAME Statement for Relational Databases.

Here is the LIBNAME statement syntax for accessing DB2 under UNIX and PC Hosts.

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

For general information about the LIBNAME statement that is not specific to SAS/ACCESS, see LIBNAME Statement in SAS Global Statements: Reference.

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.

db2

specifies the SAS/ACCESS engine name for the DB2 under UNIX and PC Hosts interface.

connection-options

provides 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 DB2 several ways. Specify only one of these methods for each connection because they are mutually exclusive.

  • USER=, PASSWORD=, DATASRC=
  • COMPLETE=
  • NOPROMPT=
  • PROMPT=
  • REQUIRED=

Here is how these options are defined.

Note: All of the following connection options are also valid in the CONNECT statement when you use the SQL pass-through facility (SQL procedure) to connect to your DBMS.
USER=<'>DB2-user-name<'>

lets you connect to a DB2 database with a user ID that is different from the default ID. USER= is optional. If you specify USER=, you must also specify PASSWORD=. If USER= is omitted, your default user ID for your operating environment is used.

Alias: UID=

PASSWORD=<'>DB2-password<'>

specifies the DB2 password that is associated with your DB2 user ID. PASSWORD= is optional. If the password contains spaces or nonalphanumeric characters, you must enclose it in quotation marks. If you specify USER=, you must specify PASSWORD=.

Alias: PWD=

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

specifies the DB2 database to which you want to connect. DATASRC= is optional. If you omit it, you connect by using a default environment variable.

Alias: DATABASE=, DB=, DSN=

COMPLETE=<'>CLI-connection-string<'>

specifies connection information for your database for PCs only. Separate multiple options with a semicolon. When a successful connection is made, 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 database. See your DB2 documentation for more details.

This option is not available on UNIX platforms.

NOPROMPT=<'>CLI-connection-string<'>

specifies connection information for your 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 in SAS windowing environment).

PROMPT=<'> CLI-connection-string<'>

specifies connection information for your database for PCs only. Separate multiple options with a semicolon. When a successful connection is made, the complete connection string is returned in the SYSDBMSG macro variable. PROMPT= does not immediately attempt to connect to the DBMS. Instead, it displays a dialog box in SAS windowing environment 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 database.

Restriction: This option is not available on UNIX platforms.

REQUIRED=<'>CLI-connection-string<'>

specifies connection information for your database for PCs only. Separate the multiple options with semicolons. When a successful connection is made, 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 available on UNIX platforms.

LIBNAME-options

specifies 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 DB2 under UNIX and PC Hosts, with the applicable default values. This table also identifies LIBNAME options that are valid in the CONNECT statement in the SQL procedure. For details, see LIBNAME Options for Relational Databases.

SAS/ACCESS LIBNAME Options for DB2 under UNIX and PC Hosts

Option

Default Value

Valid in CONNECT

ACCESS=

none

AUTHDOMAIN=

none

AUTOCOMMIT=

NO

BL_RECOVERABLE=

NO

CONNECTION=

SHAREDREAD

CONNECTION_GROUP=

none

CURSOR_TYPE=

none

DBCLIENT_MAX_BYTES=

1 for character data types

3 for graphic data types with UTF8 encoding (1 for graphic data types with other encodings)

DBCOMMIT=

1000 (when inserting rows), 0 (when updating rows), 10,000 (when bulk loading rows)

DBCONINIT=

none

DBCONTERM=

none

DBCREATE_TABLE_OPTS=

none

DBGEN_NAME=

DBMS

DBINDEX=

NO

DBLIBINIT=

none

DBLIBTERM=

none

DBMAX_TEXT=

1024

DBMSTEMP=

NO

DBNULLKEYS=

YES

DBNULLWHERE=

YES

DBPROMPT=

NO

DBSERVER_MAX_BYTES=

none

DBSLICEPARM=

NONE

DEFER=

NO

DIRECT_EXE=

none

DIRECT_SQL=

YES

FETCH-IDENTITY=

NO

IGNORE_READ_ONLY_COLUMNS=

NO

IN=

none

INSERTBUFF=

automatically calculated based on row length

POST_STMT_OPTS=

none

MULTI_DATASRC_OPT=

NONE

PRESERVE_COL_NAMES=

YES (see Naming Conventions for DB2 under UNIX and PC Hosts)

PRESERVE_COMMENTS=

NO

PRESERVE_TAB_NAMES=

YES (see Naming Conventions for DB2 under UNIX and PC Hosts)

PRESERVE_USER=

NO

PROGRAM_NAME=

none

QUERY_TIMEOUT=

0

READBUFF=

automatically calculated based on row length

READ_ISOLATION_LEVEL=

CS

READ_LOCK_TYPE=

ROW

REREAD_EXPOSURE=

NO

SCHEMA=

your user ID

SPOOL=

YES

SQL_FUNCTIONS=

none

SQL_FUNCTIONS_COPY=

none

SQLGENERATION=

none

STRINGDATES=

NO

UPDATE_ISOLATION_LEVEL=

CS (see Locking in the DB2 under UNIX and PC Hosts Interface)

UPDATE_LOCK_TYPE=

ROW

UPDATE_SQL=

YES

UTILCONN_TRANSIENT=

YES

WARN_BIGINT=

NO

DB2 under UNIX and PC Hosts LIBNAME Statement Example

In this example, the libref MyDBLib uses the DB2 engine and the NOPROMPT= option to connect to a DB2 database. PROC PRINT is used to display the contents of the DB2 table Customers.

libname mydblib db2
   noprompt="dsn=userdsn;uid=myusr1;pwd=mypwd1;";

proc print data=mydblib.customers;
   where state='CA';
run;
Last updated: February 3, 2026