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

I have a list of company names and I would like to subtract the rows with certain company names and create a new file. As company names are given in capital (WALMART), lowercase(walmart), hyphen in the middle (Wal-Mart) or mixed with other words (WALMART SUPERMARKET), I need multiple words to include. Basically, I want the observations that contain 'WALMART' or any similar word in it. 

 

Company

Walmart

WALMART

Wal-MART

WALMART SUPERMARKET

WALMART PHARMACY

 

I ran the code below, but it didn't work. 

20 data all.walmart;
21 set all.retailstore;
22 if findw(company,'WALMART')>0;
23 if findw(company,'walmart')>0 ;
24 if findw(company,'Walmart')>0 ;
25 if findw(company,'Wal-mart')>0 ;
26 if findw(company,'WAL-MART')>0 ;
27 run;
1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11
/*? Quantifier — Matches between zero and one times*/
data all.walmart;;
	set all.retailstore;
	if prxmatch('/wal-?mart/io',company);
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
if findw(company,'WALMART',' ','i')>0;

This searches ignoring case.

 

but since there can be a hyphen in the company name

 

if findw(company,'WALMART',' ','i')>0 or findw(company,'WAL-MART',' ','i')>0;

 

Or maybe this: (UNTESTED)

 

if findw(compress(company,,'p'),'WALMART',' ','i');
--
Paige Miller
r_behata
Barite | Level 11
/*? Quantifier — Matches between zero and one times*/
data all.walmart;;
	set all.retailstore;
	if prxmatch('/wal-?mart/io',company);
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 2527 views
  • 0 likes
  • 3 in conversation