Skip to content
Advertisement

Cummulative sum up to a date

I have a table with 4 columns. that looks something like this.

I want to add a1 and a2 for all rows before and up to that date, so I have something more like this:

This was my attempt. A self join up to that date:

The results are a mess and nothing lines up with my expectations. I am sure I am making a big mistake somewhere, but I would appreciate some guidance with either fixes to the proc sql or a data step.

Advertisement

Answer

A data step will make it easy. Sort it by your id and date, then use a sum statement to accumulate your values.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement