BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cruise
Ammonite | Level 13

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
PGStats
Opal | Level 21

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

View solution in original post

2 REPLIES 2
Reeza
Super User
Look up the DIF() function.
PGStats
Opal | Level 21

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

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1235 views
  • 2 likes
  • 3 in conversation