The FIRST. and LAST. are automatic variables, created for every variable used in the BY statement. They indicate a change in the values of a variable. See this:
data have;
input x;
datalines;
1
1
1
2
2
3
;
data want;
set have;
by x;
f = first.x;
l = last.x;
run;
BTW, your data step will not work, as you use FIRST. and LAST. for a variable not included in the BY.
Also note that, for BY to work, the dataset must be sorted by the variable(s), unless the NOTSORTED option is used.
The FIRST. and LAST. are automatic variables, created for every variable used in the BY statement. They indicate a change in the values of a variable. See this:
data have;
input x;
datalines;
1
1
1
2
2
3
;
data want;
set have;
by x;
f = first.x;
l = last.x;
run;
BTW, your data step will not work, as you use FIRST. and LAST. for a variable not included in the BY.
Also note that, for BY to work, the dataset must be sorted by the variable(s), unless the NOTSORTED option is used.
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss. Register now and lock in 2025 pricing—just $495!