LIBNAME Statement for the Microsoft SQL Server Engine

Overview

This section describes the LIBNAME statement as supported in SAS/ACCESS Interface to Microsoft SQL Server. For general information about this feature, see LIBNAME Statement for Relational Databases.

Here is the LIBNAME statement syntax for accessing Microsoft SQL Server.

LIBNAME libref sqlsvr <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.

sqlsvr

specifies the SAS/ACCESS engine name for the Microsoft SQL Server 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 Microsoft SQL Server in many different ways. Specify only one of these methods for each connection because they are mutually exclusive.

  • USER=, PASSWORD=, and 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=<'>user-name<'>

lets you connect to Microsoft SQL Server with a user ID that is different from the default ID.

Alias: UID=

Usage: optional

PASSWORD=<'>password<'>

specifies the Microsoft SQL Server password that is associated with your user ID.

Alias: PWD=

Usage: optional

DATASRC=<'>SQL-Server-data-source<'>

specifies the Microsoft SQL Server data source to which you want to connect. For UNIX platforms, data sources must be configured by modifying the .ODBC.ini file. This option 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=. This API is guaranteed to be present in all drivers.

Alias: DATABASE=, DB=, DSN=

COMPLETE=<'>SQL-Server-connection-options<'>

specifies connection options for your 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 database. See your driver documentation for more details.

Restriction: This option is not available on UNIX platforms.

NOPROMPT=<'>SQL-Server-connection-options<'>

specifies connection options 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 to help you with the connection string.

Aliases: CONNECTSTR=, CONNECT_STRING=

PROMPT=<'> SQL-Server-connection-options<'>

specifies connection options for your 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 in SAS Display Manager 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=<'>SQL-Server-connection-options<'>

specifies connection options for your 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.

Restriction: This option is not available on UNIX platforms.

LIBNAME-options

specify 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 Microsoft SQL Server, 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 Microsoft SQL Server

Option

Default Value

Valid in CONNECT

ACCESS=

none

AUTHDOMAIN=

none

AUTOCOMMIT=

NO

BL_ACCOUNTNAME=

none

BL_APPLICATIONID=

none

BL_COMPRESS=

NO

BL_DEFAULT_DIR=

temporary file directory that is specified by the UTILLOC= system option

BL_DELETE_DATAFILE=

YES

BL_DELIMITER=

bell character (ASCII 0x07)

BL_DNSSUFFIX=

dfs.core.windows.net

BL_FILESYSTEM=

none

BL_FOLDER=

none

BL_IDENTITY=

none

BL_LOG=

none

BL_MAXERRORS=

0

BL_OPTIONS=

none

BL_SECRET=

none

BL_TIMEOUT=

60

BL_USE_ESCAPE=

NO

BL_USE_LOG=

NO

BULKLOAD=

NO

CONNECTION=

UNIQUE when the data source supports only one cursor per connection; otherwise, SHAREDREAD

CONNECTION_GROUP=

none

CURSOR_TYPE=

DYNAMIC

DATETIME2=

NO

DBCOMMIT=

1000 (when inserting rows), 0 (when updating 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

DBSLICEPARM=

NONE

DEFER=

NO

DELETE_MULT_ROWS=

NO

DIRECT_EXE=

none

DIRECT_SQL=

YES

IGNORE_READ_ONLY_COLUMNS=

NO

INSERT_SQL=

YES

INSERTBUFF=

Calculated automatically based on row size (if INSERT_SQL=YES)

KEYSET_SIZE=

0

LOGIN_TIMEOUT=

0

MULTI_DATASRC_OPT=

NONE

POST_STMT_OPTS=

none

PRESERVE_COL_NAMES=

see Naming Conventions for Microsoft SQL Server

PRESERVE_COMMENTS=

NO

PRESERVE_GUID=

YES

PRESERVE_TAB_NAMES=

see Naming Conventions for Microsoft SQL Server

QUALIFIER=

none

QUERY_TIMEOUT=

0

QUOTE_CHAR=

none

READBUFF=

0

READ_ISOLATION_LEVEL=

RC (see Locking in the Microsoft SQL Server Interface)

READ_LOCK_TYPE=

ROW

REREAD_EXPOSURE=

NO

SCANSTRINGCOLUMNS=

NO

SCHEMA=

none

SPOOL=

YES

SQL_FUNCTIONS=

none

SQL_FUNCTIONS_COPY=

none

SQLGENERATION=

none

STRINGDATES=

NO

TRACE=

NO

TRACEFILE=

none

UPDATE_ISOLATION_LEVEL=

RC (see Locking in the Microsoft SQL Server Interface)

UPDATE_LOCK_TYPE=

ROW

UPDATE_MULT_ROWS=

NO

UPDATE_SQL=

driver-specific

USE_ODBC_CL=

NO

UTILCONN_TRANSIENT=

NO

WARN_BIGINT=

NO

Microsoft SQL Server LIBNAME Statement Examples

In this example, USER= and PASSWORD= are connection options.

libname mydblib sqlsvr user=myusr1 password=mypwd1 dsn=sqlserver;

In this next example, the libref MYDBLIB connects to a Microsoft SQL Server database using the NOPROMPT= option.

libname mydblib sqlsvr noprompt="uid=myusr1;
   pwd=mypwd1; dsn=sqlservr;" stringdates=yes;

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