SAS/ACCESS Interface to 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 |
specifies any SAS name that serves as an alias to associate SAS with a database, schema, server, or group of tables and views.
specifies the SAS/ACCESS engine name for the ODBC interface.
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.
Here is how these options are defined.
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.
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.
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;";
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.
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.
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.
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.
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=
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.
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;
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.