BookmarkSubscribeRSS Feed
sebastiaam
Obsidian | Level 7

Greetings, I have a big programming problem. The objective of my project is to calculate the loss of contracts in a certain period of months. My data is organized as follows (only two months appear, but it follows)

sebastiaam_0-1675884961042.png

The idea is to filter the live contracts in month 1, and see if they die in the following months. A contract is live if it is less than 180 days past due. That is, by filtering this table for month 1, we have the following.

sebastiaam_1-1675885120377.png

Then look in the following months the evolution of the contracts. That is, I create a loss table with the filters: Month > 1 and Delay >180
Getting the following

sebastiaam_2-1675885346412.png

The problem is that my databases are corrupted and I can't wait for my client to give me clean ones. In my loss matrix, only contract F should appear, which presents a logical evolution of the delay. Contract B takes an illogical leap in the delay, and contract I did not even appear in the previous month.

So I need to create some kind of rule or filter that doesn't make me take these contracts for the construction of the loss matrix. So, my idea is to make the following rule:
Only add the contract to the loss, if it exceeds 180 days, and also exists on the basis of the previous month with a delay difference of less than or equal to 31 days between Monthly Delay (x) and Monthly Delay (x-1). 

That is, it cannot have logical jumps in the delay, nor can it suddenly appear from one month to another.

 

And the truth is that I have no idea how to do it. In pandas I would try to do a left join with flags and only add the contracts that appear in both instances with the 'both' flag and that have logical delay evolution. But in SAS it does not occur to me.

Sorry if the question is too long and the explanation is confusing. I appreciate your help in advance.

 

2 REPLIES 2
SASJedi
SAS Super FREQ

Providing only screenshots of the data and verbal descriptions makes it pretty difficult to assess the problem and provide suggestions. Supplying code that produces a small sample of the data you are ingesting and the data you would like to have greatly boosts the chances that someone will help you fairly quickly. Adding the code you have already tried even more so. Here is an example of how to provide data:

/* Here is the data I have as input */
data have;
	input Month Register $ Balance Delay;
datalines;
1 A 50 0
1 B 120 160
2 A 50  30
2 B 120 190
3 C 100 190
;

/* Here is what I want the result to look like */
data want;
	input Month Register $ Balance Delay;
datalines;
2 B 120 190
;
Check out my Jedi SAS Tricks for SAS Users
ballardw
Super User

Missing details:

You say "A contract is live if it is less than 180 days past due". Which variable(s) tell us it is 180 days past due.

", only contract F should appear, " How do we know which is contract F?

"Monthly delay (x) and Monthly delay (x-1)" ?

This may be obvious to you but when you use anything that is not a variable in the data set we have to guess, and guessing leads to poor solutions.

 

How are your databases corrupted? Do you have an idea what caused the corruption? Backups? Source text files to re-read?

 

Note that SAS Proc SQL will do joins but I am not sure that I understand what you would join this on as it seems to missing something like identifier for client or similar.

 

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