title: Creating Cumulative Column in SAS Using PROC SQL
body: <p>I've seen ways to do this using code such as this:</p>
  
  <pre><code> data a; 
   set a; 
   xsum + x; 
   run;
  </code></pre>
  
  <p>I would prefer to be able to do this using PROC SQL.</p>
  
  <p>I have a large table with a day difference counter.  It measures multiple processes that started on the same day and tracks how long it takes for the process to terminate.  I want to add a cumulative column to this table to be able to see the overall progress of the batch of processes.  This is what I have right now:</p>
  
  <pre><code>proc sql;
  create table work.distribution as
  select unique(difference) as day_count
          ,sum(case when difference &lt;= day_count then 1 else 0 end)/count(*) as proportion
  from work.day_difference
  order by day_count;
  quit;
  </code></pre>
  
  <p>The output is just showing a full proportion for each unique difference value.</p>
  
  <p>For example:</p>
  
  <p>Difference = 0 proportion = 1</p>
  
  <p>Difference = 1 proportion = 1</p>
  
  <p>Where it should only be showing 1 at difference = 45, when all processes have completed.</p>
  
  <p>Does anybody have any ideas of tweeks that could potentially get the cumulative column to show up correctly?  </p>
  
  <p>Here is a data sample:</p>
  
  <pre><code>      init_dt  finish_dt difference
          20667   20667   0
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20668   20667   1
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
          20669   20667   2
  </code></pre>
  
  <p>Here is a sample of the output:</p>
  
  <pre><code>   day_count     proportion
      0             1
      1             1
      2             1
      3             1 
      4             1
      7             1
      8             1
      9             1
      10            1
      11            1
      14            1
      15            1
  </code></pre>