title: How to use lag function to calculate next observation in SAS
body: <p>Suppose the dataset has 3 columns</p>
  
  <pre><code>Obs  Theo  Cal  
  1    20    20   
  2    21    23   
  3    21    .    
  4    22    .    
  5    21    .    
  6    23    .    
  </code></pre>
  
  <p><code>Theo</code> is the theoretical value while <code>Cal</code> is the estimated value. </p>
  
  <p>I need to calculate the missing <code>Cal</code>.
  For each <code>Obs</code>, its <code>Cal</code> is a linear combination of previous two <code>Cal</code> values.</p>
  
  <p><code>Cal(3) = Cal(2) * &amp;coef1 + Cal(1) * &amp;coef2</code>.<br>
  <code>Cal(4) = Cal(3) * &amp;coef1 + Cal(2) * &amp;coef2</code>. </p>
  
  <p>But <code>Cal = lag1(Cal) * &amp;coef1 + lag2(Cal) * &amp;coef2</code> didn't work as I expected.</p>