Follow the
general guidelines in this table for writing efficient WHERE clauses.
Efficient WHERE Clause Guidelines
|
|
|
Avoid the NOT operator
if you can use an equivalent form.
|
Inefficient: where
zipcode not>8000
|
Efficient: where
zipcode<=8000
|
Avoid the >= and
<= operators if you can use the BETWEEN predicate.
|
Inefficient: where
ZIPCODE>=70000 and ZIPCODE<=80000
|
Efficient: where
ZIPCODE between 70000 and 80000
|
Avoid LIKE predicates
that begin with % or _ .
|
Inefficient: where
COUNTRY like '%INA'
|
Efficient: where
COUNTRY like 'A%INA'
|
Avoid arithmetic expressions
in a predicate.
|
Inefficient: where
SALARY>12*4000.00
|
Efficient: where
SALARY>48000.00
|
|
Whenever possible,
SAS/ACCESS
passes WHERE clauses to the DBMS, because the DBMS processes them
more efficiently than SAS does. SAS translates the WHERE clauses into
generated SQL code. The performance impact can be particularly significant
when you are accessing large DBMS tables. The following section describes
how and when functions are passed to the DBMS. For information about
passing processing to the DBMS when you are using PROC SQL, see
Overview: Optimizing Your SQL Usage.
If you have NULL values
in a DBMS column that is used in a WHERE clause, be aware that your
results might differ depending on whether the WHERE clause is processed
in SAS or is passed to the DBMS for processing. This is because DBMSs
tend to remove NULL values from consideration in a WHERE clause, but
SAS does not.
To prevent WHERE clauses
from being passed to the DBMS, use the
DIRECT_SQL= NOWHERE
LIBNAME option.