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

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!

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.

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