Defining a schema in SAS/ACCESS® Interface to ODBC


When you use SAS/ACCESS Interface to ODBC to connect to a database, the SAS® System looks for tables that are owned or created by the user ID that is listed in the LIBNAME statement. If the software does not find any tables associated with that user ID, the SAS log still shows that the library was assigned successfully, as shown in the following example output:

 libname mylib odbc user=user-id password=password dsn=data-source-name;
NOTE: Libref MYLIB was successfully assigned as follows:
Engine:        ODBC

However, no tables appear in the library in the SAS Explorer window, as shown here:

The library does not show any tables because there are no tables owned or created by the user ID from the LIBNAME statement. Therefore, you need to define a schema in the LIBNAME statement. A schema is the owner or creator of tables. To see tables that are owned or created by a different user, you must use the SCHEMA=schema-name option in the LIBNAME statement.

To determine the schema for your tables, follow these steps:

1. Submit the following code using your ODBC user ID, password, and ODBC data-source name:

proc sql; connect to odbc(user=userid password=password dsn=data-source-name); create table work.odbcSchema as select * from connection to odbc (ODBC::SQLTables); quit;

After you run the code, open the created table to see the schema and table names, as shown here:

2. Scroll through the Work.odbcSchema table to find the owner name for the table that you want to see.

3. Use the owner name for that table as the value in the SCHEMA= option in your LIBNAME statement. For example, if you want to see the FIRST table, you must use SCHEMA=DBITEST in the LIBNAME statement, as shown here:

libname mylib odbc user=userid password=password dsn=data-source-name schema=dbitest;

When you submit the LIBNAME statement in this example, the tables with a schema value of DBITEST appear in the Explorer window.