title: using LAG and LAST.VAR for creating variables
body: <p>I have the following dataset:</p>
  
  <pre><code>AGE    HSQ    PCT
  
  65      1     0.7
  65      2     0.2
  65      3     0.1
  66      1     0.5
  66      2     0.25
  66      3     0.25
  
  [...]
  </code></pre>
  
  <p>What I need is to get the followig output:</p>
  
  <pre><code>AGE     P1    P2     P3
  
  65     0.7    0.2    0.1
  66     0.5    0.25   0.25
  
  [...]
  </code></pre>
  
  <p>I have been told to adopt <code>LAG</code> and <code>FIRST.AGE</code> or <code>LAST.AGE</code> in order to do that, and to me it seems a good strategy. However I am not able to get the final result.. the (wrong) code I am using is:</p>
  
  <pre><code>DATA OUTPUT;
    SET SAMPLE;
      BY AGE HSQ;
    IF LAST.AGE THEN DO;
      P1=LAG2(PCT);
      P2=LAG1(PCT);
      P3=PCT;
    END;
  RUN;
  </code></pre>
  
  <p>But it jumps to previus ages percentages, which is not what I need.. where is the syntax error? Thanks!</p>