The SORT Procedure |
Restriction: | The BY statement cannot be used with the KEY statement. |
Tip: | Multiple KEY statements can be specified. |
KEY variable(s) </ option> ; |
Required Arguments |
specifies the variable by which PROC SORT orders the observations. Multiple variables can be specified. Each of these variables must be separated by a space. A range of variables can also be specified. For example, the following code shows how to specify multiple variables and a range of variables:
data sortKeys; input x1 x2 x3 x4 ; cards; 7 8 9 8 0 0 0 0 1 2 3 4 ; run; proc sort data=sortKeys out=sortedOutput; key x1 x2-x4; run;
Multiple KEY statements can also be specified. The first sort key encountered from among all sort keys is considered the primary sort key. Sorting continues for every specified KEY statement and its variables. For example, the following code shows how to specify multiple KEY statements:
proc sort data=sortKeys out=sortedOutput; key x2; key x3; run;
The following code example uses the BY statement to accomplish the same type of sort as the previous example:
proc sort data=sortKeys out=sortedOutput; by x2 x3; run;
Options |
sorts in ascending order the variable or variables that it follows. Observations are sorted from the smallest value to the largest value. The ASCENDING keyword modifies all the variables that precede it in the KEY statement.
reverses the sort order for the variable that it follows in the statement so that observations are sorted from the largest value to the smallest value. The DESCENDING keyword modifies all the variables that it precede in the KEY statement.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.