BookmarkSubscribeRSS Feed
jseb1823
Calcite | Level 5

I have a dataset for repayment loan amounts it consists of the following, perm_id( firm id), startyear endyear and date as well as repayment for each month.

I am trying to accumulate all repayment amounts per id per month and roll them off as the loans expire I have tried the following code; 

 

proc sql ;

create table dsf2 as

select a.perm_id,

       a.date,

       a.endyear,

       sum(b.repayment) as srepayment

    from dsf3 as a,

         dsf3 as b

    where a.perm_id = b.perm_id

      and b.date >= a.date

      and b.date < a.endyear

    group by a.perm_id,

       a.date,

       a.endyear;

quit;

 

 

run;

However with the multiple overlapping loans it is giving very strange results

Any ideas?

I attempted to sum the amounts by date intervals however its picking up amounts that start later on and adds then to the very beginning.

3 REPLIES 3
ballardw
Super User

Example data in the form of a working data step.

A more detailed explanation of "rolled off".

Example of the desired result for the given example data.

 

I have to say that your limited problem description sounds like it is going to be order dependent and processing data in a given order is typically not SQL's strong suit as it is intended to work on sets.

 

 

jseb1823
Calcite | Level 5

thank you for your reply;

 

Please see a breakdown in excel.

 

The repayment accumulates with each repayment and then rolls off as seen in the repayment column, first highlighted brown.

 

 

 

 

 

 

ballardw
Super User

Not even going to attempt to make your data set and can't code against a picture.

 

One reason we ask for a working data step is so we can tell the properties of the variables. It is amazing how many people ask questions about values not working and find out they are trying to add/subtract/ some other calculation with character values which turns out poorly for any number of reasons.

 

Excel and other spreadsheets are particularly crappy for data because each cell can have different types of values. So what you "see" as a date may well be text. And pictures of spreadsheet are just right out.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 616 views
  • 0 likes
  • 2 in conversation