Question : Adding a column of cumulative counts in SAS for subgroups within a larger list

Hi anyone,

Just wondering if anyone has SAS code to add a column of cumulative counts

Example of what I am after.
Cust Count  Cum Count
Peter 1  1
Peter 4 5
Peter 5 10
Peter 6 16
Peter 7 23
Janet 1 1
Janet 3 4
Janet 4 7
Mary 2 2
Mary 5 7

Answer : Adding a column of cumulative counts in SAS for subgroups within a larger list

assuming your data is stored in dataset x, and x is already sorted by cust field:
data y;
  set x;
  by cust;
  length cumulative 8.;
  retain cumulative;
  cumulative = sum(cumulative, count);
run;

don't have anything to test the code on, so if there's an error just post it back here :)
Random Solutions  
 
programming4us programming4us