Previous Page | Next Page

Working with Grouped or Sorted Observations

Review of SAS Tools


Procedures

PROC SORT <DATA=SAS-data-set> <OUT=SAS-data-set> <NODUPRECS>;

sorts a SAS data set by the values of variables listed in the BY statement. If you specify the OUT= option, the sorted data are stored in a different SAS data set than the input data. The NODUPRECS option tells PROC SORT to eliminate identical observations.


Statements

BY <DESCENDING> variable-1 < . . . <DESCENDING> variable-n>;

in a DATA step causes SAS to create FIRST. and LAST. variables for each variable named in the statement. The value of FIRST.variable-1 is 1 for the first observation with a given BY value and 0 for other observations. Similarly, the value of LAST.variable-1 is 1 for the last observation for a given BY value and 0 for other observations. The BY statement can follow a SET, MERGE, MODIFY, or UPDATE statement in the DATA step; it cannot be used with an INPUT statement. By default, SAS assumes that data being read with a BY statement are in ascending order of the BY values. The DESCENDING option indicates that values of the variable that follow are in the opposite order, that is, largest to smallest.

Previous Page | Next Page | Top of Page