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-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!

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.

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
  • 4 replies
  • 29025 views
  • 4 likes
  • 4 in conversation