FIRST. and LAST. DATA Step Variables

How the DATA Step Identifies BY Groups

In the DATA step, SAS identifies the beginning and end of each BY group by creating the following two temporary variables:
  • FIRST.variable
  • LAST.variable
The temporary variables are available for DATA step programming, but they are not added to the output data set. Their values indicate whether an observation is one of the following positions:
  • the first one in a BY group
  • the last one in a BY group
  • neither the first nor the last one in a BY group
  • both first and last, as is the case when there is only one observation in a BY group

How SAS Determines FIRST.variable and LAST.variable

  • When an observation is the first in a BY ...

Get SAS Certified Specialist Prep Guide now with O’Reilly online learning.

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