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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2636 views
  • 0 likes
  • 3 in conversation