title: Conditional/Partitioned Running Total in SAS
body: <p>I'm trying to create a new column called &quot;new Value&quot; that is the running total of an existing column - partitioned by several identifiers.</p>
  <blockquote>
  <p>x = 1 to 10</p>
  <p>_i_member reads off of an array {members} that has 24 items in it</p>
  <p>_i_simul  is the actual number of members in each item in the members array</p>
  </blockquote>
  <p>Below is what members looks like:</p>
  <pre><code>array members {24} _temporary_ (5 6 8 10 12 15 20 25 30 40 50 
                                          60 70 80 90 100 125 150 175 200 250 300 400 500)
  </code></pre>
  <p>I tried using a data step:</p>
  <pre><code>data simulation_members3; 
          set claims.new_simulation_members;
          do until (last._i_member);
          by _i_member;
          New_Value + Value ;
  end;
  run;
  </code></pre>
  <p>But it doesn't work because the table isn't sorted by _i_member (_i_member = 1 repeats when x =2,3,..,24)
  The first running total that is calculated should be the total of x=1 and _i_member=1, until it hits the last _i_simul value (which in the first value of the members array is 5, second value of members array is 6, etc.)</p>
  <p>Here is what my current table looks like (called &quot;claims.new_simulation_members&quot;)</p>
  <pre><code>     x |_i_member|_i_simul|     Value      | New Value
      ---|---------|--------|----------------|-----
       1 |      1  |   1    |     10         | 10
       1 |      1  |   2    |     15         | 25 = 10 + 15
       1 |      1  |   3    |     18         | 43 = 10 + 15 + 18  
       1 |      1  |   4    |     6          | 49 = 10+15+18+6
       1 |      1  |   5    |     8          | 57 = 10+15+18+6+8
       1 |      2  |   1    |     6          | 6
       1 |      2  |   2    |     7          | 14 = 6+7
     ... |    ...  | ...    |   ...          | ...   
      10 |      1  |   1    |     4          | 4
      10 |      1  |   2    |     5          | 9 = 4+5
  </code></pre>