I have a table containing a accrual_date, absence_type, employee_id and duration_days.
accrual_date absence_type duration_days employee_id
01JAN2001:00:00:00 010 10.20 1
01JAN2001:00:00:00 014 11 1
01JAN2002:00:00:00 015 30 2
01JAN2001:00:00:00 015 20 2
I would like to create a query that sum the duration_days per emplid per absence type. So the result should be like:
employee_id duration_days_010 duration_days_014 duration_days_015
1 10.20 11 .
2 . . 50
Add a column containing the duration_daysper absence_type per employee_id:
proc sql;
create table sort_second as
select
case when absence_type='014' then sum(duration_days) else . end as duration_days_014,
case when absence_type='015' then sum(duration_days) else . end as duration_days_015,
case when absence_type='010' then sum(duration_days) else . end as duration_days_010,
employee_id, absence_type
from sort_first
group by emplid;
quit;
Then remove the duplicate keys:
proc sort data=sort_second out=test1 nodupkey;
by emplid;
quit;
But what this code does is disregards that it's from 014 or 015 or 010 and add it all for an employee. Like this:
employee_id duration_days_010 duration_days_014 duration_days_015
1 21.20 21.20 .
2 . . 50
Kindly advise what went wrong. Thank you in advance.