BookmarkSubscribeRSS Feed
MikeR_Indy_
Calcite | Level 5

Let me start by saying I'm new. Very new.

I have three data sets:

BEGINNING_BALANCE has account_number, date, available_Balance, and currency_type.

SMALL_FIN has account_number, date, currency_type, relation_number, and transaction_amt.

ELIGIBLE_ACCOUNT has account_number, date, and relation_number.

I need to know if an eligible transaction occurred without a fee. In order to solve for this, I need to take the available_balance from the BEGINNING_BALANCE table and then add all eligible transactions to date listed on the SMALL_FIN table to get the actual amount available when the transaction occurred. This is further complicated because it's possible for one account to have multiple transactions on the same day. So i have to make sure that my results show the total amount available on the account for each unique account number, date, and relation number combination. I need to make sure that the relation numbers from ELIGIBLE_ACCOUNT match SMALL_FIN.

I know logically what needs to happen but when i try to work it out in SQL i get awful results. I've gotten far enough to create these three tables from larger disparate data sources but now i'm stuck. Any help would be really appreciated. Please let me know if i need to clarify anything or if I've left out details you may need. Again, thanks for any help, I really appreciate it. C

4 REPLIES 4
Reeza
Super User

Mike,

Can you post (very small) example of your data and expected result as data.  De-identify it where required and try and make sure the data matches the output.

Sometimes its easier to work backwards, from the smaller table to the bigger ones or it could be easier in a datastep, but I'm having a hard time understanding at the moment. 

MikeR_Indy_
Calcite | Level 5

Sure . . .

BEGINNING_BALANCE

account_Number          Date               Available_Balance               Currency_type

1234567                    09SEP2013          0.00                                   DL

2345678                    09SEP2013          0.00                                   DL

SMALL_FIN

Account_Number          Date          trans_amt          Currency_type          Relation_Num

2345678                    11SEP2013     100.00               DL                         1

2345678                    11SEP2013     0.00                    DL                         2

ELIGIBLE_Account

Account_Number          Date                    Relation_Num    

2345678                         11SEP2013          1

2345678                         11SEP2013          2

So given the above data, i'd want my results to look like this:

Account Number               date               Currency_type          Relation Number          Net_Balance

2345678                    11SEP2013          DL                                        2                         0.00

Since account 1234567 isn't on the ELIGIBLE_ACCOUNT table it isn't included in the results. Since relation 1 on account 2345678 has a trans_amt > 0.00 it isn't included but relation 2 is. Does that help?

Reeza
Super User

Why do need the beginning balance table?

Does this get you closer?

proc sql;

     create table want as

     select e.*, s.currency_type, s.trans_amt

from elegible_account e

join small_fin s

on e.account_number=s.account_number
and e.relation_num=s.relation_num

and s.trans_amt=0;

quit;

MikeR_Indy_
Calcite | Level 5

I need to solve for the amount available on the account. We only record the balance in a snapshot . . . The BEGINNING BALANCE table gives me a moment in time where i know the account balance. If someone starts with 500 on their account a transaction of 0 is fine. Without the Beginning balance i'd see that as a free transaction.

I'll try the query you suggested.

Thanks Reeza.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 786 views
  • 0 likes
  • 2 in conversation