04-12-2018 05:31 PM
For example, I have 3 months of data stacking like this, and this is what I want to ask. I want to create a new data set based on this one but in which I want to delete accounts having balance constantly below 100 threshold since month 1 and forward. And I would like to repeat the same process for individual month #2, #3 until the end of of my data set. With that purpose, the code should only delete account 1D, 2A and 2D for month 1 and account 4A for month 2. This is just an example represented what I want to do. My actual data is way bigger than this. It has at least 50 months of data so I am looking for a MACRO SAS DO loop that can help me perform what I would like to. Thanks a lot.
04-24-2018 02:35 AM
04-12-2018 05:51 PM
No macro needed. Something like this should work
/* UNTESTED CODE */ proc summary data=have; class account_number; var balance; output out=maxbal max=max_balance; run; proc sort data=have; by account_number; run; /* Delete any account_number that has max_balance < 100 */ data want; merge have maxbal; by account_number; if max_balance<100 then delete; run;
04-13-2018 01:44 AM
Your rule does not make sense. Why would you delete A4 for month 2, when it has a balance of 125, which is > 100 AFAIK?
Only account 1D satisfies your rule for deleting.
04-13-2018 09:42 AM
That's not your rule:
I quote from your initial post:
delete accounts having balance constantly below 100 threshold since month 1
(emphasis by me)
Please make up your mind and post a clear and correct rule.
04-13-2018 09:57 AM
Sorry If I am not that clear. What I want is that for month 1, I want to delete all accounts having balance constantly below 100 since month 1. But then in month 2, I want to delete all accounts having balance constantly below 100 since month 2, etc. Is it clear now?
04-13-2018 10:02 AM
04-13-2018 10:14 AM
Sorry I do apologize for that example. but pretty much this is what I wanna do. For individual snapshot, I want to delete accounts that staying below 100 since that particular snapshot
04-13-2018 10:18 AM
So, apparently I have misunderstood the requirements, and so the code I gave is not correct.
let me make sure I have the requirements understood properly now.
You want to delete accounts where the values are always under 100 after the first month that the account appears. The first month the account appears could be over 100, and we still delete the account if all subsequent months are under 100.
Is that a correct understanding?
04-13-2018 10:40 AM
I want to delete accounts where the values are always under 100 after the month its value starts dropping below 100. So for account 4A example, since its value is above 100 in month 2, it should be kept in month 2 snapshot. But if its value keeps staying below 100 since month 3 (where its value dropped below 100), it should be deleted from the dataset since month 3 snapshot and in later subsequent months. So in your final data, you still see account 4A in month 2, but not in month 3 and forward. Hopefully this is clear. Please let me know if I need to clarify it more.
04-13-2018 10:48 AM
I want to delete accounts where the values are always under 100 after the month its value starts dropping below 100.
This is different than what I thought and different than previous explanations. So, if we have a longer time series and a certain account has values
we would include this account in month 1, include this account in month 2, include this account in month 3, but not include the account after month 3.
If the sequence of data is
then the account is always included. Is that right?
04-13-2018 11:05 AM
I will try my best here. For your example,
For give those value in month #1, if the last 4 account have values going back above 100 in month #5, I want to keep them in month 1, month 2, #3, #4 and #5 as long as its value above 100. but then if one of those starts dropping below 100 (for example in month #6) and constantly stay below until the end of series, then it should be deleted since month #6. Is that clear?
04-13-2018 11:09 AM - edited 04-13-2018 11:10 AM
Not clear at all.
Why don't we delete the account at month 4? All the values are below 100 at month 4 and beyond.
04-13-2018 11:16 AM
but if I do that, it may delete some accounts that may go above 100 in later months. cause if it goes above 100 in later months, I dont want to delete them in current months unless its value is always below 100 since current month.
04-13-2018 11:21 AM
cause I want to model attrition rate. We dont care about accounts with balance below 100 dollars. But if we just simply deleted account with below 100 for each particular month, it will overstate attrition rate for that month. Because when accounts dropped below 100, it does not actually meant it leaves the bank. But right now by deleting those, it is pretty much I assume they leave the bank for that month (account balance < 100) but actually they do not.
Need further help from the community? Please ask a new question.