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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 814 views
  • 1 like
  • 2 in conversation