title: Conditional sum using proc sql
body: <p>I have a table containing a accrual_date, absence_type, employee_id and duration_days. </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I would like to create a query that sum the duration_days per emplid per absence type. So the result should be like:</p>
  
  <pre><code>employee_id       duration_days_010   duration_days_014  duration_days_015
  1                 10.20               11                 .
  2                 .                   .                  50
  </code></pre>
  
  <p>Add a column containing the duration_daysper absence_type per employee_id:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Then remove the duplicate keys:</p>
  
  <pre><code>proc sort data=sort_second out=test1 nodupkey;
  by emplid;
  quit;
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>employee_id       duration_days_010   duration_days_014  duration_days_015
      1                 21.20               21.20          .
      2                 .                   .                  50
  </code></pre>
  
  <p>Kindly advise what went wrong. Thank you in advance.</p>