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;
/*? Quantifier — Matches between zero and one times*/
data all.walmart;;
set all.retailstore;
if prxmatch('/wal-?mart/io',company);
run;
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');
/*? Quantifier — Matches between zero and one times*/
data all.walmart;;
set all.retailstore;
if prxmatch('/wal-?mart/io',company);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.