The observations in a SAS data set can be ordered (sorted) by specific variables. To sort a SAS data set, first close the
data set if it is open. Then submit a SORT statement and specify the ordering variables. You can also specify an output data
set name if you do not want to overwrite the original data set. For example, the following statements create a new SAS data
set named Sorted
:
proc iml; sort Sashelp.Class out=Sorted by name;
The new data set contains the observations from the data set Sashelp.Class
, ordered by the variable Name
. If you omit the OUT= option, the original data set is replaced by the sorted data set.
You can specify multiple sort variables. Optionally, each variable can be preceded by the keyword DESCENDING, which denotes that the subsequent variable is to be sorted in descending order.