/*Data must be sorted or indexed for BY-group processing*/ proc sort data=prog2.flymiles out=milesort; by ID; run; data freqmiles(drop=miles); set milesort; by ID; /*BY statement create First.ID and Last.ID*/ if First.ID then TotMiles=0; /*Set TotMiles to 0 when ID changes*/ TotMiles+Miles; /*sum statement creates TotArea, retains it, sets initial value to 0, and ignores missing values of size*/ if Last.ID then output; /*Output only the last of each BY group*/ run; /*Create a list report of the data set to verify the output*/ proc print data=freqmiles; run;