How SAS Uses the Sort Indicator to Improve Performance
The sort information provided by the sort indicator is used internally for performance
improvements. There are several ways to improve performance using the sort indicator:
SAS uses the sort indicator to validate whether there was a previous sort. If there was
a previous sort from a SORT procedure or an SQL procedure with an ORDER BY
clause, then SAS does not perform another sort.
The SORT procedure sets the sort indicator when a sort occurs. The SORT
procedure checks for the sort indicator before it sorts a data set so that data is not
re-sorted unnecessarily. For more information, see the SORT Procedure in the
Base SAS Procedures Guide.
The SQL procedure uses the sort indicator to process queries more efficiently and
to determine whether an internal sort is necessary before performing a join. For
more information, see the SQL procedure in the Base SAS Procedures Guide.
When using the sort indicator during index creation, SAS determines whether the
data is already sorted by the key variable or variables in ascending order by checking
the sort indicator in the data file. If the values in the sort indicator are in ascending
order, SAS does not sort the values for the index file. For more information, see
“Understanding SAS Indexes” on page 638.
When processing a WHERE expression without an index, SAS first checks the sort
indicator. If the Validated sort information is YES, SAS stops reading the file once
there are no more values that satisfy the WHERE expression.
If an index is selected for WHERE expression processing, the sort indicator for that
data set is changed to reflect the order that is specified by the index.
For BY-group processing, if the data set is already sorted by the BY variable, SAS
does not use the index, even if the data set is indexed on the BY variable.
If the Validated sort information is set to YES, SAS does not need to perform
another sort.
Validating That a Data Set Is Sorted
Any SAS procedure that requires data to be sorted as part of the process checks the sort
indicator information. The sort indicator is set when a data set is sorted by a SORT
procedure, an SQL procedure with an ORDER BY clause, a DATASETS procedure
MODIFY statement, or a SORTEDBY= data set option. If the SORT or SQL procedures
were used to sort the data set, the CONTENTS procedure output indicates the Validated
sort information is YES. If the SORTEDBY= data set option was used to sort the data
set, the CONTENTS procedure output indicates the Validated sort information is NO.
For examples of the CONTENTS procedure output, see “Example 1: Using No Sorting”
on page 598, “Example 2: Using the SORTEDBY= Data Set Option” on page 599, and
“Example 3: Using the SORT Procedure” on page 601.
You can use the SORTVALIDATE system option to specify whether the SORT
procedure validates that a data set is sorted correctly when the data set sort indicator
shows that a user has specified that the data set is sorted. The user can specify a sort
order by using the SORTEDBY= data set option in a DATA statement or by using the
SORTEDBY= option in the DATASETS procedure MODIFY statement. When the sort
indicator is set by a user, SAS cannot be absolutely certain that a data set is sorted
according to the variables in the BY statement.
Sorted Data Sets 603
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.181