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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.