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-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!

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