Using BY-Group Processing

Finding the First and Last Observations in a Group

Creating List Reports explained how to use a BY statement in PROC SORT to sort observations and in PROC PRINT to group observations for subtotals. You can also use the BY statement in the DATA step to group observations for processing.
data temp; 
   set salary; 
   by dept; 
run;
When you use the BY statement with the SET statement, here are requirements and results:
  • The data sets that are listed in the SET statement must either be sorted by the values of the BY variables, or they must have an appropriate index.
  • The DATA step creates two temporary variables for each BY variable. One is named FIRST.variable, where variable is the name of the BY variable, and ...

Get SAS Certification Prep Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.