title: SAS- Counting Occurences happening during a given time period
body: <p>I am trying to write a simple code to count number of services provided each year for a variety of providers, based on a single original column. Ideally my output would simplistically look something like:</p>
  
  <p>Input data would look something like this:</p>
  
  <pre><code>Prov_ID    Name    Service_Cd  Date
  A          Joe     B2           02JUN2012
  A          Joe     C9           04OCT2013
  A          Joe     B2           12JUL2014
  B          Steve   A1           12MAR2012
  B          Steve   E4           20OCT2013
  C          Tom     B10          23SEP2012
  ...        ...     ...          ...
  ...        ...     ...          ...
  </code></pre>
  
  <p>AND So on, with the goal being to be have a unique provider id on, a total services performed, and then totals per year 2012, 2013, 2014.  </p>
  
  <pre><code>ProvID  Name  Service_Count  2012_Count  2013_Count  2014_Count
  A       Joe    12             4            6            2
  B       Steve  15             5            5            5 
  C       Tom    22             10           8            4
  </code></pre>
  
  <p>A dulled down current version of the code I have written for this particular task includes:</p>
  
  <pre><code>proc sql;
  CREATE TABLE provider_detail as
      SELECT distinct(PROV_ID), COUNT(distinct Service_CD)AS Service_Count, COUNT (date between '01JAN2012'd AND '31DEC2012'd)AS 2012_Count,COUNT (date between '01JAN2013'd AND '31DEC2013'd)AS 2013_Count,COUNT (date between '01JAN2014'd AND '31DEC2014'd)AS 2014_Count
      FROM primary1
      Group BY PROV_ID;
      run;
  </code></pre>
  
  <p>But doing so I get the same count in each column. Any help would be greatly appreciated as I am new to SAS and still learning the ropes so to say. Thank you!</p>