From: William Shakespeare on
I have data that are sorted by customer number and transaction date. I
want to flag the first and last transaction for each customer:

proc sort data=sasdata.have;
by id date;
run;

data sasdata.want;
set sasdata.have;
by id;
if first.date then first_flag=1;else first_flag=0;
if last.date then last_flag=1;else last_flag=0;
run;

SAS successfully executes the sort and then runs the data step with this
note:

NOTE: Variable first.date is uninitialized.
NOTE: Variable last.date is uninitialized.

These variables exist. What am I doing wrong?