Selecting a SAS/ACCESS Method

Methods for Accessing DBMS Tables and Views

You can often complete a task in SAS/ACCESS in several ways. For example, you can access DBMS tables and views by using the LIBNAME statement or the SQL pass-through facility. Before processing complex or data-intensive operations, you might want to test several methods first to determine the most efficient one for your particular task.

SAS/ACCESS LIBNAME Statement Advantages

You should use the SAS/ACCESS LIBNAME statement for the fastest and most direct method of accessing your DBMS data except when you need to use SQL that is not ANSI-standard. ANSI-standard SQL is required when you use the SAS/ACCESS library engine in the SQL procedure. However, the SQL pass-through facility accepts all SQL extensions that your DBMS provides.
Here are the advantages of using the SAS/ACCESS LIBNAME statement.
  • Significantly fewer lines of SAS code are required to perform operations on your DBMS. For example, a single LIBNAME statement establishes a connection to your DBMS, lets you specify how data is processed, and lets you easily view your DBMS tables in SAS.
  • You do not need to know the SQL language of your DBMS to access and manipulate data on your DBMS. You can use such SAS procedures as PROC SQL or DATA step programming on any libref that references DBMS data. You can read, insert, update, delete, and append data. You can also create and drop DBMS tables by using SAS syntax.
  • The LIBNAME statement gives you more control over DBMS operations such as locking, spooling, and data type conversion through the use of LIBNAME and data set options.
  • The engine can optimize processing of joins and WHERE clauses by passing them directly to the DBMS, which takes advantage of the indexing and other processing capabilities of your DBMS. For more information, see Overview: Optimizing Your SQL Usage.
  • The engine can pass some functions directly to the DBMS for processing.

SQL Pass-Through Facility Advantages

Here are the advantages of using the SQL pass-through facility.
  • You can use SQL pass-through facility statements so the DBMS can optimize queries, particularly when you join tables. The DBMS optimizer can take advantage of indexes on DBMS columns to process a query more quickly and efficiently.
  • SQL pass-through facility statements let the DBMS optimize queries when queries have summary functions (such as AVG and COUNT), GROUP BY clauses, or columns that expressions create (such as the COMPUTED function). The DBMS optimizer can use indexes on DBMS columns to process queries more rapidly.
  • On some DBMSs, you can use SQL pass-through facility statements with SAS/AF applications to handle transaction processing of DBMS data. Using a SAS/AF application gives you complete control of COMMIT and ROLLBACK transactions. SQL pass-through facility statements give you better access to DBMS return codes.
  • The SQL pass-through facility accepts all extensions to ANSI SQL that your DBMS provides.

SAS/ACCESS Features for Common Tasks

Here is a list of tasks and the features that you can use to accomplish them.
SAS/ACCESS Features for Common Tasks
Task
SAS/ACCESS Features
Read DBMS tables or views
LIBNAME statement1
SQL pass-through facility
View descriptors2
Create DBMS objects, such as tables
LIBNAME statement1
DBLOAD procedure
SQL pass-through facility EXECUTE statement
Update, delete, or insert rows into DBMS tables
LIBNAME statement1
View descriptors2
SQL pass-through facility EXECUTE statement
Append data to DBMS tables
DBLOAD procedure with APPEND option
LIBNAME statement and APPEND procedure1
SQL pass-through facility EXECUTE statement
SQL pass-through facility INSERT statement
List DBMS tables
LIBNAME statement and SAS Explorer window1
LIBNAME statement and DATASETS procedure1
LIBNAME statement and CONTENTS procedure1
LIBNAME statement and SQL procedure dictionary tables1
Delete DBMS tables or views
LIBNAME statement and SQL procedure DROP TABLE statement1
LIBNAME statement and DATASETS procedure DELETE statement1
DBLOAD procedure with SQL DROP TABLE statement
SQL pass-through facility EXECUTE statement
1LIBNAME statement refers to the SAS/ACCESS LIBNAME statement.
2View descriptors refer to view descriptors that are created in the ACCESS procedure.