Hi Folks:
I have variables 'test' and 'negative' which are cumulatively added across rows. Could you please help me reverse the cumulative process? I'd like to have numbers for each row without encompassing the value in the preceding rows. I need the first 3 rows of 'test' variable 1,0,3 instead 1,1,4 before it's turned into cumulative sum across the rows?
Thanks for your time in advance.
data have;
length date $10.;
input date $ test negative;
cards;
1/20/2020 1 0
1/21/2020 1 0
1/22/2020 4 3
1/23/2020 22 21
1/24/2020 27 25
1/25/2020 27 25
1/26/2020 51 47
1/27/2020 61 56
1/28/2020 116 97
1/29/2020 187 155
1/30/2020 246 199
1/31/2020 312 245
2/1/2020 371 289
2/2/2020 429 327
2/3/2020 490 414
;
ac
Using DIF, and taking care of the first row:
data want;
set have;
dtest = coalesce(dif(test), test);
dneg = coalesce(dif(negative), negative);
run;
Using DIF, and taking care of the first row:
data want;
set have;
dtest = coalesce(dif(test), test);
dneg = coalesce(dif(negative), negative);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.