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

Hi

 

I have a dataset with a variable of "Comp_Name", it consists of the long names of various companies. I want to delete the observations where "company_name" includes specific strings e.g. ‘IDX’, ‘S&P’,  ‘DOW JONES’ and ‘MSCI’.

 

Please see the sample below:

 

Data have;
input ID Comp_Name $;
datalines;
 105246 AARI Growth S&P: Social Principl Inst.
 105246 AARI Growth S&P: Social Principl Inst.
 105290 Atlas Assets Inc. Health Servc
 105290 Atlas Assets Inc. Health Servc
 105290 Atlas Assets Inc. Health Servc
 116020 AARE Income: Invst IDX
 147001 Evergreen Select: Dow Jones: Diversified Value
 147001 Evergreen Select: Dow Jones: Diversified Value
; run;

 

I want the following:

 

Data want;
input ID Comp_Name $;
datalines;
 105290 Atlas Assets Inc. Health Servc
 105290 Atlas Assets Inc. Health Servc
 105290 Atlas Assets Inc. Health Servc
; run;

 

Need your guidance. Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Better add \b for matching a word ,not a string.

 

Data have;
input ID $ Comp_Name $50.;
infile datalines missover;
datalines;
105246 AARI Growth S&P: Social Principl Inst.
105246 AARI Growth S&P: Social Principl Inst.
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
116020 AARE Income: Invst IDX
147001 Evergreen Select: Dow Jones: Diversified Value
147001 Evergreen Select: Dow Jones: Diversified Value
;

data want;
   set have;
   if prxmatch('/\b(idx|dow jones|msci|s&p)\b/oi',Comp_Name) then delete;
run;

proc print;run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Do like this

 

Data have;
input ID $ Comp_Name $50.;
infile datalines missover;
datalines;
105246 AARI Growth S&P: Social Principl Inst.
105246 AARI Growth S&P: Social Principl Inst.
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
116020 AARE Income: Invst IDX
147001 Evergreen Select: Dow Jones: Diversified Value
147001 Evergreen Select: Dow Jones: Diversified Value
;

data want;
   set have;
   where prxmatch("m/idx|dow jones|msci|s&p/oi",Comp_Name)=0;
run;
Ksharp
Super User

Better add \b for matching a word ,not a string.

 

Data have;
input ID $ Comp_Name $50.;
infile datalines missover;
datalines;
105246 AARI Growth S&P: Social Principl Inst.
105246 AARI Growth S&P: Social Principl Inst.
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
105290 Atlas Assets Inc. Health Servc
116020 AARE Income: Invst IDX
147001 Evergreen Select: Dow Jones: Diversified Value
147001 Evergreen Select: Dow Jones: Diversified Value
;

data want;
   set have;
   if prxmatch('/\b(idx|dow jones|msci|s&p)\b/oi',Comp_Name) then delete;
run;

proc print;run;
Saba1
Quartz | Level 8
Thanks. It is so helpful.

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