DATA or PROC step processing
using the default Base SAS engine requires that if there is no index
or if the observations are not in order, the data set must be sorted
before a BY statement is issued. In contrast, by default, the SPD
Engine sorts the data returned to the application if the observations
are not in order. Unlike PROC SORT, which creates a new sorted data
set, the SPD Engine's automatic sort does not change the permanent
data set and does not create a new data set. However, utility file
space is used. For more information, see
SPDEUTILLOC= System Option.
The default is BYSORT=YES.
A BYSORT=YES argument enables the automatic sort, which outputs the
observations in BY group order. If the data set option BYNOEQUALS=YES,
then the observations within a group might be output in a different
order from the order in the data set. Set BYNOEQUALS=NO to retain
data set order.
The BYSORT=NO argument
means that the data must already be sorted on the specified BY variables.
This result can be from a previous sort using PROC SORT, or from
the data set having been created in BY variable order. When BYSORT=NO,
grouped data is delivered to the application in data set order. Indexes
are not used to retrieve the observations in BY variable order. The
data set option BYNOEQUALS= has no effect when BYSORT=NO.
If you specify the BYSORT=
option in the LIBNAME statement, it can be overridden by specifying
BYSORT= in the PROC or DATA steps. Therefore, you set BYSORT=NO in
the LIBNAME statement and subsequently a BY statement is encountered.
An error occurs unless your data has been sorted (either by previously
using PROC SORT or because it was created in sorted order). Set BYSORT=YES
in the DATA or PROC step, for input or update opens, to override BYSORT=NO
in the LIBNAME statement. The point is that BYSORT=NO instructs the
engine to do nothing to sort the data.
When you use the BYSORT=YES
and the IDXWHERE= data set options, the following messages are written
to the SAS log if you set the MSGLEVEL=I SAS system option:
-
If IDXWHERE=YES and there is an
index on the BY variable, the index is used to order the rows of the
table. The following message is written to the SAS log:
Note: BY ordering was produced by using an index for table tablename.
-
If IDXWHERE=NO or IDXWHERE=YES
and there is no index on the BY variable, SPD Engine performs an automatic
sort to order the rows of the table. The following message is written
to the SAS log:
Note: BY ordering was produced by performing an automatic
sort on table tablename.