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

Hi, 

 

Good Morning!! Looking to get some help from the community. 

 

I have a dataset with transaction information for each customers and below is what the data looks like today. 

 

Customer id      Trans_date            Transaction Amount          Account Balance

12345                12-Nov-17              50                                     50

12345                14-Nov-17              40                                     90

12345                17-Nov-17              -25                                    65

23564                10-Nov-17              15                                     15

23564                18-Nov-17              15                                     30

 

Basically, every time a single transaction results in increase in account balance, is what I want to capture by customer id (highlighted in red). 

 

Looking for some expert advice and help. 

 

Thanks

 

--TJ

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use the DIF or LAG function to retreive the previous value or difference from previous value.

 

data want;
set have;

by customerID;

change=dif(account_balance);

if not first.customerId and change>0 then output;

run;

@BhararaTej wrote:

Hi, 

 

Good Morning!! Looking to get some help from the community. 

 

I have a dataset with transaction information for each customers and below is what the data looks like today. 

 

Customer id      Trans_date            Transaction Amount          Account Balance

12345                12-Nov-17              50                                     50

12345                14-Nov-17              40                                     90

12345                17-Nov-17              -25                                    65

23564                10-Nov-17              15                                     15

23564                18-Nov-17              15                                     30

 

Basically, every time a single transaction results in increase in account balance, is what I want to capture by customer id (highlighted in red). 

 

Looking for some expert advice and help. 

 

Thanks

 

--TJ


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Use the DIF or LAG function to retreive the previous value or difference from previous value.

 

data want;
set have;

by customerID;

change=dif(account_balance);

if not first.customerId and change>0 then output;

run;

@BhararaTej wrote:

Hi, 

 

Good Morning!! Looking to get some help from the community. 

 

I have a dataset with transaction information for each customers and below is what the data looks like today. 

 

Customer id      Trans_date            Transaction Amount          Account Balance

12345                12-Nov-17              50                                     50

12345                14-Nov-17              40                                     90

12345                17-Nov-17              -25                                    65

23564                10-Nov-17              15                                     15

23564                18-Nov-17              15                                     30

 

Basically, every time a single transaction results in increase in account balance, is what I want to capture by customer id (highlighted in red). 

 

Looking for some expert advice and help. 

 

Thanks

 

--TJ


 

BhararaTej
Fluorite | Level 6

Thanks.. I ended up using the lag function and this worked. 

 

--TJ

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 797 views
  • 1 like
  • 2 in conversation