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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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