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 Certification Prep Guide, 5th 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.