FIRST. and LAST. variables: Data step processing within by groups using the SET statement
FIRST. and LAST. variables: Data step processing within by groups If you use a by statement along with a set statement in a data step then SAS creates two automatic variables, FIRST.variable and LAST.variable, where variable is the name of the by variable. FIRST.variable has a value 1 for the first observation in the by group and 0 for all other observations in the by group. LAST.variable has a value 1 for the last observation in the by group and 0 for all other observations in the by group. The code shown below is available here . data temp; input group x; cards; 1 23 1 34 1 . 1 45 2 78 2 92 2 45 2 89 2 34 2 76 3 31 4 23 4 12 ; run; /************************************************** The automatic variables first.group and last.group are not saved with the data set. Here we write them to data set variables to show their contents. **************************************************/ data new; set temp; by group; first=first.group; last=last.group; run; proc print; title 'Raw data al...