BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dogo23
Quartz | Level 8

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

novinosrin
Tourmaline | Level 20

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

Dogo23
Quartz | Level 8

This worked, thanks!

HB
Barite | Level 11 HB
Barite | Level 11

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%.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 31535 views
  • 4 likes
  • 4 in conversation