title: SAS Count how many times a value has changed over time
body: <p>I have a dataset that has weekly values stored by location.  I want to determine how many times the value has changed.  Initially I thought I could just count distinct values, but the issue is that sometimes the values are repeated.  Consider the example below:</p>
  
  <pre><code>data have;
      input location $ week value;
  cards;
  NC 1 100
  NC 2 200
  NC 3 200
  NC 4 200
  NC 5 100
  NC 6 200
  SC 1 500
  SC 2 500
  SC 3 500
  SC 4 500
  SC 5 500
  SC 6 500
  ;
  run;
  </code></pre>
  
  <p>Notice that the value at location NC changes three times, at weeks 2,5,6.  The value at location SC changes 0 times.</p>
  
  <p>I would like an output of the change frequency...something like:</p>
  
  <pre><code>NC 3
  SC 0
  </code></pre>
  
  <p>Any help would be greatly appreciated.  Thank you.</p>