SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ismahero2
Obsidian | Level 7

HI,

I am trying to find a way to find character fields that contains some special keywords. 

I tried using something like this:

IF TINT='2' and NAME CONTAINS (' TRUST ', ' TR ');

TINTNAME
1JOSEPH BROWN TRUST
2THE TRUSTWORTHDY TRUST CORP
2JOHN ADAMS TR

I would like to find a way to identify , in this example, the last two observations because they meet the conditions I listed on the IF statement.  I do have millions of records, so this is just an example. Any ideas how to make this easy?

Thanks...

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

How many key "words" are you needing to search for? You aren't going to find a list type function though it may be possible to write one.

FINDW lets you specify only to match words, which are separated by delimiters such as a space so you do not need to try to specify a search string such as ' TR ' with spaces to find the TR at the end of line 3 but not match if in the middle of a word.

 

 

if tint='2' then do;
/* multiple individual searches*/
     if findw(name,'TRUST')>0 then do; <whatever>; end;
     if findw(name,'TR')>0 then do; <whatever>; end;
end;

And from @DBailey:

Others have given data step suggestions...you could also use proc sql (especially if the data are in a rdbms somewhere else)...

 

proc sql;
select * from have where
TINT='2' and
( NAME like '% TRUST %' or name like  '% TR %');
quit;

 

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

IF TINT='2'

  and ( INDEXW( NAME,'TRUST')

    or  INDEXW( NAME,'TR')

       )

;

ballardw
Super User

How many key "words" are you needing to search for? You aren't going to find a list type function though it may be possible to write one.

FINDW lets you specify only to match words, which are separated by delimiters such as a space so you do not need to try to specify a search string such as ' TR ' with spaces to find the TR at the end of line 3 but not match if in the middle of a word.

 

 

if tint='2' then do;
/* multiple individual searches*/
     if findw(name,'TRUST')>0 then do; <whatever>; end;
     if findw(name,'TR')>0 then do; <whatever>; end;
end;

And from @DBailey:

Others have given data step suggestions...you could also use proc sql (especially if the data are in a rdbms somewhere else)...

 

proc sql;
select * from have where
TINT='2' and
( NAME like '% TRUST %' or name like  '% TR %');
quit;

 

stat_sas
Ammonite | Level 13

data want(drop=_name keywords);

set have;

_NAME=NAME;

length keywords $20;

do keywords='TRUST', 'TR';

_NAME = tranwrd(_NAME,strip(keywords),'***');

end;

if TINT=2 and findw(_name,'***');

run;

DBailey
Lapis Lazuli | Level 10

Others have given data step suggestions...you could also use proc sql (especially if the data are in a rdbms somewhere else)...

proc sql;

select * from have where

TINT='2' and

( NAME like '% TRUST %' or name like  '% TR %');

quit;

Ksharp
Super User

IF TINT='2'

  and  prxmatch('/TRUST|TR/',NAME)

;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 191762 views
  • 4 likes
  • 6 in conversation