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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Per<strong>for</strong>mance Considerations 4 Sorting DBMS Data 37Repeatedly Accessing DataCAUTION:If you need to access the most current DBMS data, access it directly from the databaseevery time. Do not follow the extraction suggestions in this section. 4It is sometimes more efficient to extract (copy) DBMS data to a <strong>SAS</strong> data file than torepeatedly read the data by using a <strong>SAS</strong> view. <strong>SAS</strong> data files are organized to provideoptimal per<strong>for</strong>mance with PROC and DATA steps. Programs that use <strong>SAS</strong> data files areoften more efficient than <strong>SAS</strong> programs that read DBMS data directly.Consider extracting data when you work with a large DBMS table and plan to use thesame DBMS data in several procedures or DATA steps during the same <strong>SAS</strong> session.You can extract DBMS data to a <strong>SAS</strong> data file by using the OUT= option, a DATAstep, or <strong>ACCESS</strong> procedures.Sorting DBMS DataSorting DBMS data can be resource-intensive—whether you use the SORTprocedure, a BY statement, or an ORDER BY clause on a DBMS data source or in theSQL procedure SELECT statement. Sort data only when it is needed <strong>for</strong> your program.Here are guidelines <strong>for</strong> sorting data.3 If you specify a BY statement in a DATA or PROC step that references a DBMSdata source, it is recommended <strong>for</strong> per<strong>for</strong>mance reasons that you associate the BYvariable (in a DATA or PROC step) with an indexed DBMS column. If youreference DBMS data in a <strong>SAS</strong> program and the program includes a BY statement<strong>for</strong> a variable that corresponds to a column in the DBMS table, the <strong>SAS</strong>/<strong>ACCESS</strong>LIBNAME engine automatically generates an ORDER BY clause <strong>for</strong> that variable.The ORDER BY clause causes the DBMS to sort the data be<strong>for</strong>e the DATA orPROC step uses the data in a <strong>SAS</strong> program. If the DBMS table is very large, thissorting can adversely affect your per<strong>for</strong>mance. Use a BY variable that is based onan indexed DBMS column in order to reduce this negative impact.3 The outermost BY or ORDER BY clause overrides any embedded BY or ORDERBY clauses, including those specified by the DBCONDITION= option, thosespecified in a WHERE clause, and those in the selection criteria in a viewdescriptor. In the following example, the EXEC_EMPLOYEES data set includes aBY statement that sorts the data by the variable SENIORITY. However, when thatdata set is used in the following PROC SQL query, the data is ordered by theSALARY column and not by SENIORITY.libname mydblib oracle user=testuser password=testpass;data exec_employees;set mydblib.staff (keep=lname fname idnum);by seniority;where salary >= 150000;run;proc sql;select * from exec_employeesorder by salary;3 Do not use PROC SORT to sort data from <strong>SAS</strong> back into the DBMS because thisimpedes per<strong>for</strong>mance and has no effect on the order of the data.

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

Saved successfully!

Ooh no, something went wrong!