title: SAS generate sequence number by group
body: <p>I need to create a sequence number by group in SAS and accumulate by group.</p>
  <p>I have a dataset with a column that it says if an event occurs o not as well as the time in case of occurrence. I also have initial datetime and end datetime which I don't represent in my example data.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Event</th>
  <th>Time</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.3</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.4</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.4</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.1</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I need to assign a sequence number for each group where the event happens and create a cumulative.</p>
  <p>It should look something like:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Event</th>
  <th>Time</th>
  <th>Group</th>
  <th>Cumulative</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.3</td>
  <td>1</td>
  <td>1.1</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.4</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.4</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.1</td>
  <td>2</td>
  <td>0.6</td>
  </tr>
  <tr>
  <td>1</td>
  <td>0.5</td>
  <td>2</td>
  <td>0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I was using the retain function with no luck.</p>
  <p>Thanks for your suggestions.
  Regards</p>