BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
noemi_b
Obsidian | Level 7

Hi all,

I am using SAS University Edition v.9.4. and I am working on a dataset that detect when a customer is about to churn from a bank.

Now, I need the following task to be performed by SAS and hoefully you can help. But first, let me provide you with a small datastep of my sample:

data have;
input customer_id_ano year month churn;
cards;
1 2017 1 0
1 2017 2 0
1 2017 3 0
1 2017 4 0
1 2017 5 0
1 2017 6 0
1 2017 7 0
1 2017 8 0
1 2017 9 1
1 2017 10 1
1 2017 11 1
1 2017 12 1
2 2017 1 0
2 2017 2 0
2 2017 3 0
2 2017 4 1
2 2017 5 1
2 2017 6 1
2 2017 7 1
2 2017 8 1
2 2017 9 1
2 2017 10 1
2 2017 11 1
2 2017 12 1
3 2017 1 1
3 2017 2 1
3 2017 3 1
3 2017 4 1
3 2017 5 1
3 2017 6 1
3 2017 7 1
3 2017 8 1
3 2017 9 1
3 2017 10 1
3 2017 11 1
3 2017 12 1
4 2017 1 0
4 2017 2 0
4 2017 3 0
4 2017 4 1
4 2017 5 1
4 2017 6 1
4 2017 7 1
4 2017 8 1
4 2017 9 1
4 2017 10 1
4 2017 11 1
4 2017 12 1
5 2017 1 0
5 2017 2 1
5 2017 3 1
5 2017 4 1
5 2017 5 1
5 2017 6 1
5 2017 7 1
5 2017 8 1
5 2017 9 1
5 2017 10 1
5 2017 11 1
5 2017 12 1
;
run;

Now, what I need is SAS to detect when the variable churn is 1 for the first time and delete all the observations following that event. In other words, instead of a list of 1s following the first churn event, I only need to keep the first 1 and delete the remaining ones. 

Let´s take customer_id_ano 1 as an example. We can see from the data step above that the variable churn for this customer is 1 starting from September 2017 and it remains 1 until the end of the observation period. Well, I only want the first churn=1 that occurred in September to remain in my dataset and the following observation must be dropped from it. 

I hope I managed to explai myself. And I would like to thank you in advance for the help you always provide to all the SAS beginners like me. Very appreciated!!

1 ACCEPTED SOLUTION
2 REPLIES 2

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1210 views
  • 1 like
  • 2 in conversation