BookmarkSubscribeRSS Feed
newboy1218
Quartz | Level 8

Hi, I have a table contains customer ID, account #s,  each month's balance (OS bal) of the accounts. Each customer can have multiple accounts in the dataset.

 

What I want is to calculate on each customer, the total outstanding balance from all accounts currently on file when a new account is open (let's call it 'Total_Customer_OSBal').

 

For example, a customer has 3 accounts, one opened in Jan 2022, one opened in Mar 2022, and the last one opened in Jun 2022. The 'Total_Customer_OSBal' for the 1st account when it opened in Jan 2022 is $0. The 'Total_Customer_OSBal' for the 2nd account when it opened in Mar 2022 is the OS balance from the 1st account in Mar 2022. The 'Total_Customer_OSBal' for the 3rd account when it opened in Jun 2022 is the OS balance from the 1st account in Jun 2022 and 2nd account in Jun 2022.

 

Is there an efficient way to do this?

 

Here are the example chart for illustration:

 

HAVE

Customer_IDAccount_numDate_OpenSnap_DateBalance
11AMAR2022MAR2022500
11AMAR2022APR2022450
11AMAR2022MAY2022400
11BMAY2022MAY2022600
22AJAN2022JAN2022100
22AJAN2022FEB202290
22AJAN2022MAR202280
22AJAN2022APR202270
22AJAN2022MAY202260
22BJAN2022JAN2022210
22BJAN2022FEB2022190
22BJAN2022MAR2022170
22BJAN2022APR2022150
22BJAN2022MAY2022130
22CMAY2022MAY2022700

 

WANT

Customer_IDAccount_numDate_OpenSnap_DateBalanceTotal_Customer_OSBal
11AMAR2022MAR20225000
11AMAR2022APR2022450.
11AMAR2022MAY2022400.
11BMAY2022MAY2022600400
22AJAN2022JAN2022100.
22AJAN2022FEB202290.
22AJAN2022MAR202280.
22AJAN2022APR202270.
22AJAN2022MAY202260.
22BJAN2022JAN2022210100
22BJAN2022FEB2022190.
22BJAN2022MAR2022170.
22BJAN2022APR2022150.
22BJAN2022MAY2022130.
22CMAY2022MAY2022700190 (60+130)

 

1 REPLY 1
HB
Barite | Level 11 HB
Barite | Level 11

Your "want" makes no sense to me.  Are there more decision rules? Why are there no Total_Customer_OSBal balances for customer 2 for Feb, Mar, Apr, and May?

  

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 310 views
  • 0 likes
  • 2 in conversation