BookmarkSubscribeRSS Feed
PS185
Calcite | Level 5

Hello,

 

I have 2 input data sets shown below

Table 1     
DateAcctRankTxnTypeATxnTypeBTxnTypeC
Jan 1 20181231701050
Jan 1 20181232100500
Jan 1 20181233301040

 

Table 2  
DateAcctAmt
Feb 1 201812350
March 1 201812350
April 1 2018123300

 

The Amt value from table 2 should be used to reduce each of the TxnTypeA/TxnTypeB/TxnTypeC amounts in the order of the Rank specified.

 

For example the 50 from Feb in table 2 should first reduce the 70 from table 1. In this case the result is table 3 as follows. I have also shown how the subsequent amounts of 50 and 300 from table 2 will update the values in table 1.

 

Output Table 3     
DateAcctRankTxnTypeATxnTypeBTxnTypeC
Feb 1 2018123170-50=201050
Feb 1 20181232100500
Feb 1 20181233301040
March 1 2018123120-20=01050
March 1 20181232100-30=70500
March 1 20181233301040
March 1 20181231010-10=050-50=0
March 1 2018123270-70=050-50=00
March 1 2018123330-30=010-10=040-40=0

 

The example above is for illustration, I have more columns and many accounts. I was thinking of using arrays but I am not sure how to process the above. Would be glad for any suggestions that the community has, thanks!

2 REPLIES 2
Tom
Super User Tom
Super User

You need explain the rules much better.

When/Why do you move from RANK=1 to RANK=2 etc.?  When/Why do you move from first column to second column?

 

Also what do the dates mean? Are they important?

PS185
Calcite | Level 5

I was attempting to explain the rules using an example but clearly that didn't do it

 

The ranks are pre-defined. Table 1 shows transactions for a given month (Jan 2019). Table 2 has payments received in subsequent months (Feb-April 2019), these payments should be applied each month to the balances in Table 1 but in the order of the rank specified.

So, in this example, payment amounts received should offset the balances in column TxnTypeA first, and within that column, in the order of increasing rank. Once all of TxnTypeA has been paid off, then the same logic should be followed on the next column TxnTypeB, again in the order of the rank specified.

Thanks for your help in advance!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 459 views
  • 0 likes
  • 2 in conversation