The GROUPFORMAT Option
The GROUPFORMAT option can be used in the data step to apply by-group processing to formatted ranges of values.
In order to use this option, the BY variable in question must have the relevant format applied. This option can only be used in the data step. Reading a SAS data set, using the GROUPFORMAT option on the BY statement, will then generate FIRST. and LAST. variables based on the formatted values as opposed to the raw column values. This is particularly useful when it is desirable to perform by-group processing when working with continuous data. See example below which totals up the number of employees in each salary band and produces a report.
data payroll; input staffno $ salary; datalines; 001 13592.45 002 8870.23 003 12672.26 004 23760.82 005 10512.63 006 7520.61 007 28512.66 008 14840.27 009 47520.38 020 23760.44 run; proc format;
0 - < 20000 = 'Under 20k'
20000 - < 30000 = 'Between 20-30k'
30000 - high = 'Over 30k';
proc sort data=payroll;
format salary salary_bands.;
by groupformat salary;
if first.salary then count_staff=0;
if last.salary then output;
proc print data=employee_salary noobs label;
label count_staff = 'No. of Employees'
salary = 'Salary Bands';