13.07.2015 Views

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Optimizing Your SQL Usage 4 Passing Functions to the DBMS Using WHERE Clauses 47The DISTINCT operator is passed to Oracle and generates this Oracle code:select distinct custbase."STATE" from CUSTBASEOracle then passes the results from this query back to <strong>SAS</strong>.Optimizing the Passing of WHERE Clauses to the DBMSGeneral Guidelines <strong>for</strong> WHERE ClausesFollow these general guidelines <strong>for</strong> writing efficient WHERE clauses.3 Avoid the NOT operator if you can use an equivalent <strong>for</strong>m.Inefficient: where zipcode not>8000Efficient: where zipcode= and =70000 and ZIPCODE12*4000.00Efficient: where SALARY>48000.003 Use DBKEY=, DBINDEX=, and MULTI_DATASRC_OPT= when appropriate. See“Using the DBINDEX=, DBKEY=, and MULTI_DATASRC_OPT= Options” on page48 <strong>for</strong> details about these options.Whenever possible, <strong>SAS</strong>/<strong>ACCESS</strong> passes WHERE clauses to the DBMS, because theDBMS processes them more efficiently than <strong>SAS</strong> does. <strong>SAS</strong> translates the WHEREclauses into generated SQL code. The per<strong>for</strong>mance impact can be particularlysignificant when you are accessing large DBMS tables. The following section describeshow and when functions are passed to the DBMS. For in<strong>for</strong>mation about passingprocessing to the DBMS when you are using PROC SQL, see “Overview of OptimizingYour SQL Usage” on page 41.If you have NULL values in a DBMS column that is used in a WHERE clause, beaware that your results might differ depending on whether the WHERE clause isprocessed in <strong>SAS</strong> or is passed to the DBMS <strong>for</strong> processing. This is because DBMSs tendto remove NULL values from consideration in a WHERE clause, while <strong>SAS</strong> does not.To prevent WHERE clauses from being passed to the DBMS, use the LIBNAMEoption DIRECT_SQL= NOWHERE.Passing Functions to the DBMS Using WHERE ClausesWhen you use the <strong>SAS</strong>/<strong>ACCESS</strong> LIBNAME statement, <strong>SAS</strong>/<strong>ACCESS</strong> translatesseveral <strong>SAS</strong> functions in WHERE clauses into DBMS-specific functions so they can bepassed to the DBMS.In the following <strong>SAS</strong> code, <strong>SAS</strong> can translate the FLOOR function into a DBMSfunction and pass the WHERE clause to the DBMS.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!