title: Fill the blank values of a variable with the previous non blank value SAS 9.3
body: <p>I'm using a dataset which is something like :</p>
  
  <pre><code>+----------+--------+-------+
  | Variable | Level  | Value |
  +----------+--------+-------+
  | sexe     | men    |    10 |
  |          | female |    20 |
  | age      | 0-20   |     5 |
  |          | 20-40  |     5 |
  |          | 40-60  |    10 |
  |          | &gt;60    |    10 |
  +----------+--------+-------+
  </code></pre>
  
  <p>And I would like to fulfill the "blank" cells using the previous non-blank cell to obtain something like this.</p>
  
  <pre><code>+----------+--------+-------+
  | Variable | Level  | Value |
  +----------+--------+-------+
  | sexe     | men    |    10 |
  | sexe     | female |    20 |
  | age      | 0-20   |     5 |
  | age      | 20-40  |     5 |
  | age      | 40-60  |    10 |
  | age      | &gt;60    |    10 |
  +----------+--------+-------+
  </code></pre>
  
  <p>I tried various possibilities in DATA step mostly with the <a href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm" rel="noreferrer">LAG()</a> function. The idea was to read the previous row when the cell was empty and fill with that.</p>
  
  <pre><code>DATA test;
     SET test;
  
     IF variable = . THEN DO;
        variable = LAG1(variable);
     END;
  RUN;
  </code></pre>
  
  <p>And I obtained</p>
  
  <pre><code>+----------+--------+-------+
  | Variable | Level  | Value |
  +----------+--------+-------+
  |          | men    |    10 |
  | sexe     | female |    20 |
  |          | 0-20   |     5 |
  | age      | 20-40  |     5 |
  |          | 40-60  |    10 |
  |          | &gt;60    |    10 |
  +----------+--------+-------+
  </code></pre>
  
  <p>The problem was the good string is not always just one row upper. But I don't understand why SAS put blank in the first and 3d line. It didn't have to modify this line because I said "If variable = .".
  I know how to do this in Python or in R with some for loop but I didn't find good solution in SAS.</p>
  
  <p>I tried to put the string inside a variable with "<a href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000210266.htm" rel="noreferrer">CALL SYMPUT</a>" and also with "<a href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214163.htm" rel="noreferrer">RETAIN</a>" but it didn't work too.</p>
  
  <p>There must be a simple and elegant way to do this. Any idea? </p>