06-13-2015 10:19 AM
I had four conditions to be passed on status variable.
If customer don`t have service 01 then customer should have a status "Other"
If customer last 6m sales is blank customer should have status "Call BACK"
If customer dont last 9m sales and in last 6m sales is blank customer should have a status "Gone"
If customer had sales in the last 6 m and last 9 m then customer should have a status "Active"
I tried to replicate these condition to SAS but at the moment ,I had only the status "others" that work fine and the status "call back" is passed
on to my all customers even though some of them should have a status "gone" or "active".
Below is my attempt to code the conditions :
if (Service ^= "01") then status = "Others";
else if (Service = "01") and ('last 6m sales' <= '0') and ('last 9m sales' <= '0') then Status = "Gone";
else if (Service = "01") and ('last 6m sales' <= '0') then Status = "Call Back";
Here you can see what the output should be.
|Customer||Service||Sales last 6||Sales last 9||Status|
The only thing I can see it that instead to type <=0 as a condition it should be about looking for missing values?
Thanks in advance.
06-15-2015 10:18 AM
Assuming in the output table "Sales last 6" is equal to the variable in your IF Statement 'last 6m sales', you need to have an "n" afterwards so SAS can read your variable with the spaces in it. So, instead of 'last 6m sales'<='0' it should be 'last 6m sales'n<='0'. I would also look into adding a condition for missing values as you mentioned at the end for the Sales last variables.
Hope that helps!
06-15-2015 11:24 AM
Is the 01 condition zero and one or letter o and 1? Your example data appears to show both Zero and Capital O. If your data is mixing these which is the condition to search for?
06-15-2015 01:17 PM
Try nested IF statements containing DO statements for efficiency:
Not sure if it's possible to have last 6m sales blank and last 9m sales not blank, but if you have to have last 6m sales to get last 9m sales, then this should work for you:
If Service^="O1" then do;
If "last 6m sales"n^="" AND "last 9m sales"n="" then Status="Call Back";
Else if "last 6m sales"n="" AND "last 9m sales"n="" then Status="Gone";
Else Status="Active"; end;