The dataset WORK.SALARY is sorted by the variable department. As the statement if first.department then is used after statement by department, SAS identifies the beginning and end of each BY group via creating two temporary variables for each BY variable: FIRST.department and LAST.department. These two temporary variables are available for DATA step programming but are not added to the output data set.
Each time a new department value appears in processing, the retained variable payroll is set to value '0'. For each department it accumulates a total of values in a group of department. Subsetting the statement if last.department; will allow the output to write only when the last record of a department group occurs; here variable payroll contains the sum of wagerate values for a department group.
The one and only FREE resource for general SAS online training as well as study guides for the SAS Base Certification. My goal is to create the SAS Certification prep guide that I never found but always wanted. This should also be a place to come if you are new to the language but are simply looking for online SAS training.