Hi,
I'm using SAS Universitiy Edition. Can anyone guide me how to write this in data step based on condition below:
If any employee get appl = 'P' and n_indi = 'In' then will be tagged as 'A1' under new_ind. (A1 repeat for subsequent row under same name)
If any employee get appl = 'P' and n_indi = 'Co' then will be tagged as 'A2' under new_ind. (A2 repeat for subsequent row under same name)
My Output:
| | employee_name | appl | n_indi | new_ind |
1 | AAA | P | Co | A2 |
2 | AAA | Gu | In | N |
3 | AAA | Gu | In | N |
4 | BBB | P | In | A1 |
5 | BBB | Gu | In | N |
6 | BBB | Gu | In | N |
7 | CCC | P | Co | A2 |
8 | CCC | P | Co | N |
9 | DDD | P | In | A1 |
10 | DDD | Gu | In | N |
11 | EEW | Gu | In | N |
Desired Output:
| | employee_name | appl | n_indi | new_ind |
1 | AAA | P | Co | A2 |
2 | AAA | Gu | In | A2 |
3 | AAA | Gu | In | A2 |
4 | BBB | P | In | A1 |
5 | BBB | Gu | In | A1 |
6 | BBB | Gu | In | A1 |
7 | CCC | P | Co | A2 |
8 | CCC | P | Co | A2 |
9 | DDD | P | In | A1 |
10 | DDD | Gu | In | A1 |
11 | EEW | Gu | In | Error |
My script
data employee;
input employee_name $ appl $ n_indi $;
datalines;
AAA Gu In
AAA P Co
AAA Gu In
BBB Gu In
BBB P In
BBB Gu In
CCC P Co
CCC P Co
DDD P In
EEE Gu In
FFF Gu In
;
run;
proc sort data= employee
out= employee2;
by employee_name descending appl ;
run;
data employee3;
set employee2;
by employee_name descending appl;
if first.employee_name and appl = 'P' and n_indi = 'Co' then new_ind = 'HPA2' ;
else if appl = 'P' and n_indi = 'In' then new_ind = 'HPA1' ;
retain new_ind;
else new_ind = 'N';
;run;