title: How to fix the first row on repeated measures
body: <p>I'm trying to translate a SAS code into R but I don't know how to translate the follow SAS code below:</p>
  
  <pre><code>data df; by id area;
  if first.area and area = 'A' then do;
  var1_sum = 0;
  var2_sum = 0;
  end;
  if indicator = 'A' then do;
  var1_sum + var1;
  var2_sum + var2;
  end;
  </code></pre>
  
  <p>From the dataset before:</p>
  
  <pre><code>id  area    var1    var2
  1   A   9   9
  1   A   4   8
  1   A   5   2
  1   B   1   4
  1   B   8   5
  1   B   0   6
  1   C   3   7
  1   C   2   8
  </code></pre>
  
  <p>We get the follow result when the SAS code above it's used:</p>
  
  <pre><code>id  area    var1    var2    var1_sum    var2_sum
  1   A   9   9   9   9
  1   A   4   8   13  17
  1   A   5   2   18  19
  1   B   1   4   1   4
  1   B   8   5   9   9
  1   B   0   6   9   15
  1   C   3   7   3   7
  1   C   2   8   5   15
  </code></pre>
  
  <p>I am using dplyr to code in R. So, I have started "a portion" of the R code which I am trying to translate, but I don't know how to code the "if condition" stated in SAS:</p>
  
  <pre><code>df &lt;- df %&gt;%
    group_by(id, area) %&gt;%
    .....
  </code></pre>
  
  <p>I am looking for help how to include the "if condition" for this case.</p>
  
  <p>Thank you for your help.</p>
  
  <p>Kind regards,</p>
  
  <p>Rungo.</p>