title: Calculating moving averages in SAS
body: <p>I am relatively new to SAS and need to calculate a moving average based on a variable. 
  I've made some example code to explain:</p>
  
  <pre><code>DATA testData;
  input shop year sales;
  datalines;
  01 01 20000
  01 02 23500
  01 03 21020
  02 01 23664
  02 02 15420
  02 03 14200
  03 01 25623
  03 02 12500
  03 03 20030
  ;
  run; 
  
  DATA average;
  retain y 0;
  set testData;
  y = y + sales;
  avg = y/_n_;
  run;
  </code></pre>
  
  <p>This gives me the average for all my sales. What I want to do is only get the averages per shop and based on the last year and then on all years of that shop. Then to start again for the next shop. Hopefully this makes some kind of sense. I don't want the moving average of any of shop 1's years to affect the average in shop 2.</p>