BookmarkSubscribeRSS Feed
Jamie_H
Fluorite | Level 6

I have a dataset that contains multiple rows per account.  The number of rows = the number of months since an account has been open, with the first row being zero.


The table shows how the balance has changed each row (month).  I would like to calculation what the expected balance change should have been had the customer kept to their agreed schedule of payments. 

 

For the first row (where AgeInMonths = 0), the ExpectedBalance should always be equal to the InitialLoanAmount.

For subsequent rows, I need to work out what the ExpectedBalance was for the row before and apply an Interest & Repayment calculation to that value to come up with that months ExpectedBalance. 

I need to continue doing this until i get to a new AccountNumber where I should start again.

 

Does anyone know how I would do this?  

Thanks

Jamie

1 REPLY 1
Astounding
PROC Star

Making some reasonable guesses about what your variable names are and what formulas should be applied:

 

data want;

set have;

by AccountNumber;

retain Expected_Balance;

if first.AccountNumber then Expected_Balance = InitialLoanAmount;

else do;

   Expected_Change = Expected_Balance * (1 + Interest) - Repayment;

   Expected_Balance = Expected_Balance + Expected_Change;

end;

run;

 

This program is obviously untested, and assumes that your data set is sorted in order by AccountNumber AgeinMonths.

  

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 744 views
  • 0 likes
  • 2 in conversation