🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-01-2020 08:59 PM
(1447 views)
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
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Using DIF, and taking care of the first row:
data want;
set have;
dtest = coalesce(dif(test), test);
dneg = coalesce(dif(negative), negative);
run;
PG
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Look up the DIF() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Using DIF, and taking care of the first row:
data want;
set have;
dtest = coalesce(dif(test), test);
dneg = coalesce(dif(negative), negative);
run;
PG