Hi all,
In a case statement, I have multiple values I was to catch in a url code. Since the full urls vary, but with a few strings that are consistently embedded within it, I want to catch them all by asking for like '%string%'. However, I don't know how to do that within a case statement and with multiple possibilities.
case when activity_id = 2 and link_name like in ('%CUSTSERV%' , '%CUSTOMER%', '%SERVICE%') then 1 else 0 end as cust_serv,
Thanks for the help ahead of time.
case when activity_id = 2 and (link_name like '%CUSTSERV%' or link_name like '%CUSTOMER%' or link_name '%SERVICE%' ) then 1 else 0 end as cust_serv
It never hurts to provide some example data in the form of a data step that demonstrates what you have and then what you want the result for that data to be.
It may be that a data step is more flexible for multiple OR comparisons. I don't think "in" operator is going to work the way you are thinking.
case when activity_id = 2 and (link_name like '%CUSTSERV%' or link_name like '%CUSTOMER%' or link_name '%SERVICE%' ) then 1 else 0 end as cust_serv
This worked, thanks!
Just for completeness since OP 1) did not post data, 2) did not provide a lot of details, and 3) those playing along at home may have trouble following things:
data records;
input id activity_id link_name:$200.;
datalines;
1105 1 whodoo_whoodoo_customer.asp
1106 1 whodate_customer_dare.html
1107 1 nothing_here_move_along.css
1108 2 has_a_target_customer_word.html
1109 2 does_not.html
1110 2 service.html
1111 2 this_is_custservice_now.html
1112 2 just_ignore_me
;
run;
proc sql;
create table customer_ones as
select
id,
case
when activity_id = 2 and (link_name like '%custserv%' or link_name like '%customer%' or link_name like '%service%')
then 1
else 0
end as cust_serv
from records;
quit;
And a note that it is case sensitive so that %CUSTOMER% is different than %customer%.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.