Understanding the Tools for Processing Information in Groups

Processing BY Groups in the DATA Step

When combining SAS data sets in a DATA step, it is often convenient or necessary to process observations in BY groups (that is, groups of observations that have the same value for one or more selected variables). Many examples in this book use BY-group processing with one or more SAS data sets to create a new data set.

The BY statement identifies one or more BY variables. When using the BY statement with the SET, MERGE, or UPDATE statement, your data must be sorted or indexed on the BY variable or variables.

In a DATA step, SAS identifies the beginning and end of each BY group by creating two temporary variables for each BY variable: FIRST.

Get Combining and Modifying SAS® Data Sets: Examples Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.