BookmarkSubscribeRSS Feed
bnarang
Calcite | Level 5

Hi Experts

Can you please help me with below problem.

I have some transaction data consecutive and I need to find out which rows consitute the total sum. Below the example:

ID     Total     Transaction     Counter
1     20          3                    1

1     20          7                    2

1     20          5                    3

1     20          5                    4

1     20          8                    5

1     20          1                    6

2     30          10                    1

2     30          10                    2

2     30          12                    3

2     30          8                    4

2     30          2                    5

I need to output the transactions which adds to the total sum. Consider the data is sorted by date and I would only need the most recent. My output should be below:

ID     Total     Transactions     Counter

1     20          3                    1

1     20          7                    2

1     20          5                    3

1     20          5                    4

2     30          10                    2

2     30          12                    3

2     30          8                    4

Transactions would be consecutive only, but range has to be decided based on the calculation. Can you please help me with the hints or solution.

Thanks

1 REPLY 1
LinusH
Tourmaline | Level 20

Sounds like you try to reverse engineer some report data? Perhaps you could get back to the source to get an id of the total calculation?

I don't see a date column, but you might refer to Counter? And how do you mean by recent in this case, you example seems to show the opposite...?

But given your desired output, just use a sum variable, together with a first. logic and explicit output (all in the data step).

Data never sleeps

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1000 views
  • 0 likes
  • 2 in conversation