data want;
set have;
by year;
if first.year then runsum=number;
else runsum+number;
run;
The FIRST. reference is incorrect, you need to use variable listed in the By statement.
@toomanystepsint wrote:
I have a dataset.
It has 3 variables:
-year
-date
-number
I want the cumulative value of number resetting every year.
The typical sas advice does not work for me.
For example, according to this answer my code should be:
data want;
set have;
by year;
if first.date then runsum=number;
else runsum+number;
run;
But this code gives me all null values for runsum. Why? That makes no sense. There's nothing I'm doing that the other answers aren't doing, this just isn't working.
I've tried many other things, including adding a retain, and doing by year and date. Retain does nothing, all my values are just null. Doing by year and date just sets runsum to the value of number, it never cumulates. I've tried turning my date variable into datetime, into character, nothing works. Why?
... View more