BookmarkSubscribeRSS Feed
Jeandas
Calcite | Level 5

Hi all,

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";

run;

Here you can see what the output should be.

CustomerServiceSales last 6Sales last 9Status
AO12Call Back
BO232Others
cO111Active
dO1Gone

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.

6 REPLIES 6
naveen20jan
Obsidian | Level 7

Hi ,

Could you please check the query as u have used variable ' last 3m ' in the question and its not there in the output .

Jeandas
Calcite | Level 5

Hi,

Sorry bad typography I edited the post

Thanks

Jean

dcruik
Lapis Lazuli | Level 10

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!

Derek

ballardw
Super User

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?

Jeandas
Calcite | Level 5

Hi

The condition is O1 ,the letter O and 1.

I will edit my example is should be O1  not zero and one.

Thanks

dcruik
Lapis Lazuli | Level 10

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:

data want;

set have;

If Service^="O1" then do;

     Status="Others"; end;

Else 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;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1108 views
  • 0 likes
  • 4 in conversation