BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello,

I have the following problem-

I have 2 data sets:

Data set Have1  with columns: CustID (Customer ID) Loan_ID (Loan ID) and 12 months of follow up period that we need to check if customer is in failure 

Note- the dates are in structure YYMM (numeric field)

 

Data set Have2 with columns: CustID (Customer ID) ,mon ( month in YYMM numeric structure), IND (indicator binary for failure)

 

Target- I need to check for each CustID+Loan_ID  if there is failure in the following up months only!

How can I do it please?

Please note that for customer 111 there are 2 loans and each loan has different follow up period

 

 


Data have1;
input CustID Loan_ID Mon1 Mon2 Mon3 Mon4 Mon5 Mon6 Mon7 Mon8 Mon9 Mon10 Mon11 Mon12;
cards;
111 121212 2307 2308 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406
111 333333 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406 2407 2408
222 777777 2307 2308 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406
;
Run;

Data have2;
input CustID mon Ind;
cards;
111 2306 1
111 2307 0
111 2308 0
111 2309 0
111 2310 0
111 2311 0
111 2312 0
111 2401 0
111 2402 0
111 2403 0
111 2404 0
111 2405 0
111 2406 0
111 2407 1
111 2408 1
111 2409 1
111 2410 1
111 2411 1
111 2412 1
222 2306 0
222 2307 0
222 2308 0
222 2309 0
222 2310 0
222 2311 0
222 2312 0
222 2401 0
222 2402 0
222 2403 0
222 2404 0
222 2405 0
222 2406 0
222 2407 0
222 2408 0
222 2409 0
222 2410 0
222 2411 0
222 2412 0
;
Run;

Data want;
input CustID Loan_ID Max_Ind_in_FollowUp;
cards;
111 121212 0
111 333333 1
222 777777 0
;
Run;

 

 

1 REPLY 1
Ksharp
Super User

Data have1;
input CustID Loan_ID Mon1 Mon2 Mon3 Mon4 Mon5 Mon6 Mon7 Mon8 Mon9 Mon10 Mon11 Mon12;
cards;
111 121212 2307 2308 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406
111 333333 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406 2407 2408
222 777777 2307 2308 2309 2310 2311 2312 2401 2402 2403 2404 2405 2406
;
Run;

Data have2;
input CustID mon Ind;
cards;
111 2306 1
111 2307 0
111 2308 0
111 2309 0
111 2310 0
111 2311 0
111 2312 0
111 2401 0
111 2402 0
111 2403 0
111 2404 0
111 2405 0
111 2406 0
111 2407 1
111 2408 1
111 2409 1
111 2410 1
111 2411 1
111 2412 1
222 2306 0
222 2307 0
222 2308 0
222 2309 0
222 2310 0
222 2311 0
222 2312 0
222 2401 0
222 2402 0
222 2403 0
222 2404 0
222 2405 0
222 2406 0
222 2407 0
222 2408 0
222 2409 0
222 2410 0
222 2411 0
222 2412 0
;
Run;
data want;
 if _n_=1 then do;
   if 0 then set have2;
   declare hash h(dataset:'have2(where=(Ind=1))');
   h.definekey('CustID','mon');
   h.definedone();
 end;
set have1;
array x{*} Mon:;
Max_Ind_in_FollowUp=0;
do i=1 to dim(x);
 if h.check(key:CustID,key:x{i})=0 then do; Max_Ind_in_FollowUp=1;leave;end;
end;
keep CustID Loan_ID Max_Ind_in_FollowUp;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 392 views
  • 0 likes
  • 2 in conversation