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
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.