BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

Hello

For each customer I have 12 months follow up with indicator of failure (1/0).

I want to know when is the last month (closest month to today: today is month index 12) that customer enter to failue.

For example:

Customer 111: month 9

Customer 222: month 11

Customer 333: Null Since today not in failure).

Customer 444: month 1 since he was always in failure)

Pay attention that if customer not in failure today then get value null.

What is the way to calculate it please?

 


Data have;
input CustID monindex failureInd;
cards;
111 1 0
111 2 0
111 3 1 
111 4 1
111 5 0
111 6 0
111 7 1 
111 8 0
111 9 1
111 10 1
111 11 1
111 12 1
222 1 0
222 2 0
222 3 0 
222 4 0
222 5 0
222 6 0
222 7 0 
222 8 0
222 9 0
222 10 0
222 11 1
222 12 1
333 1 0
333 2 0
333 3 0 
333 4 0
333 5 0
333 6 0
333 7 0 
333 8 0
333 9 1
333 10 1
333 11 0
333 12 0
444 1 1
444 2 1
444 3 1 
444 4 1
444 5 1
444 6 1
444 7 1 
444 8 1
444 9 1
444 10 1
444 11 1
444 12 1
;
Run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Data have;
input CustID monindex failureInd;
cards;
111 1 0
111 2 0
111 3 1 
111 4 1
111 5 0
111 6 0
111 7 1 
111 8 0
111 9 1
111 10 1
111 11 1
111 12 1
222 1 0
222 2 0
222 3 0 
222 4 0
222 5 0
222 6 0
222 7 0 
222 8 0
222 9 0
222 10 0
222 11 1
222 12 1
333 1 0
333 2 0
333 3 0 
333 4 0
333 5 0
333 6 0
333 7 0 
333 8 0
333 9 1
333 10 1
333 11 0
333 12 0
444 1 1
444 2 1
444 3 1 
444 4 1
444 5 1
444 6 1
444 7 1 
444 8 1
444 9 1
444 10 1
444 11 1
444 12 1
;
Run;


data temp;
 set have;
 by CustID failureInd notsorted;
 if first.failureInd ;
run;

data want;
 set temp;
 by CustID;
 if failureInd=0 then call missing(monindex);
 if last.CustID;
 drop failureInd;
run;

View solution in original post

1 REPLY 1
Ksharp
Super User
Data have;
input CustID monindex failureInd;
cards;
111 1 0
111 2 0
111 3 1 
111 4 1
111 5 0
111 6 0
111 7 1 
111 8 0
111 9 1
111 10 1
111 11 1
111 12 1
222 1 0
222 2 0
222 3 0 
222 4 0
222 5 0
222 6 0
222 7 0 
222 8 0
222 9 0
222 10 0
222 11 1
222 12 1
333 1 0
333 2 0
333 3 0 
333 4 0
333 5 0
333 6 0
333 7 0 
333 8 0
333 9 1
333 10 1
333 11 0
333 12 0
444 1 1
444 2 1
444 3 1 
444 4 1
444 5 1
444 6 1
444 7 1 
444 8 1
444 9 1
444 10 1
444 11 1
444 12 1
;
Run;


data temp;
 set have;
 by CustID failureInd notsorted;
 if first.failureInd ;
run;

data want;
 set temp;
 by CustID;
 if failureInd=0 then call missing(monindex);
 if last.CustID;
 drop failureInd;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 519 views
  • 1 like
  • 2 in conversation