proc sort data=cert.usa out=work.temp; /*#1*/ by dept; run; data work.budget(keep=dept payroll); /*#2*/ set work.temp; by dept; /*#3*/ if wagecat='S' then Yearly=wagerate*12; /*#4*/ else if wagecat='H' then Yearly=wagerate*2000; if first.dept then Payroll=0; /*#5*/ payroll+yearly; /*#6*/ if last.dept; /*#7*/ run;
1 | The SORT procedure sorts the data in Cert.Usa by the variable Dept. The results of the SORT procedure are stored in Work.Temp. |
2 | The KEEP= data set option keeps the variables Dept and Payroll in the output data set, Work.Budget. |
3 | The BY statement in a DATA step
applies only to the SET statement. The data set Work.Temp must be
sorted by the Dept variable for the BY statement to set up grouping
variables. By specifying Dept as the variable, you can identify the
first and last observations for each Dept group. The Dept groups are ADM10 , ADM20 , ADM30 , CAM10 ,
and CAM20 .
|
4 | The IF statement executes the statements
conditionally. If the value for WageCat is S ,
then the variable Yearly contains the value of WageRate multiplied
by 12. If the value of WageCat is H ,
then the variable Yearly contains the value of WageRate multiplied
by 2000.
|
5 | If the observation is the first
observation for the variable Dept, initialize Payroll to 0 .
Note: FIRST.Dept variable is not
written to the data set and does not appear in the output.
|
6 | Add the value of Yearly to the value of Payroll. |
7 | If this observation is the last
in the variable, Dept, then end. If not, then read the next observation.
Note: LAST.Dept variable is not
written to the data set and does not appear in the output.
|
proc print data=work.budget noobs; sum payroll; format payroll dollar12.2; run;
Coxe
, Delgado
,
and Overby
. The JobType subgroup contains
nine subgroups: 1
, 3
, 5
, 10
, 20
, 50
, 240
, 420
,
and 440
. Within these subgroups, you
can identify the first and last observations for each of these subgroups.
proc sort data=cert.usa out=work.temp2; /*#1*/ by manager jobtype; run; data work.budget2 (keep=manager jobtype payroll); /*#2*/ set work.temp2; by manager jobtype; /*#3*/ if wagecat='S' then Yearly=wagerate*12; /*#4*/ else if wagecat='H' then Yearly=wagerate*2000; if first.jobtype then Payroll=0; /*#5*/ payroll+yearly; /*#6*/ if last.jobtype; /*#7*/ run;
1 | The SORT procedure sorts the data in Cert.Usa by the variables Manager and JobType. The results of the SORT procedure are stored in Work.Temp2. |
2 | The KEEP= data set option specifies the variables Manager, JobType, and Payroll and writes the variables to the new data set, Work.Budget. |
3 | The BY statement in a DATA step applies only to the SET statement. The data set Work.Temp2 must be sorted by the Manager and JobType variables in order for the BY statement to set up grouping variables. The data set is sorted by the variable Manager first and then by JobType. |
4 | The IF statement executes the statements
conditionally. If the value for WageCat is S ,
then the variable Yearly contains the value of WageRate multiplied
by 12. If the value of WageCat is H ,
then the variable Yearly contains the value of WageRate multiplied
by 2000.
|
5 | If the observation is the first for JobType, then initialize Payroll to 0. |
6 | Add the value of Yearly to the value of Payroll. |
7 | If this observation is the last in the variable, JobType, then end. If not, then read the next observation. |
proc print data=work.budget2 noobs; by manager; var jobtype; sum payroll; where manager in ('Coxe', 'Delgado'); format payroll dollar12.2; run;