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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3162 views
  • 0 likes
  • 3 in conversation