05-24-2013 12:25 PM
I am wondering how I can do the following:
I have a data set with about 6000 rows of information - each field contains a string (something like this -> This is a sample text string)
I was wondering what I can do to "search" all the rows of information for specific key words and then only keep those in my new smaller data set.
Basically I want to say: if the words "this" "now" "then" appear in the column then keep that row or identify it somehow.
Any sample codes would be greatly appreciated!
05-24-2013 12:33 PM
I tried scan and index - both give me this error:
function call has too many arguments
I have a bunch of keywords I am searching for in my code. Like this:
05-24-2013 12:35 PM
I think only PRX functions will allow you to have multiple keywords in a single function.
Scan is used to substr or subset a sentence though, not search through it.
if find(var_1, "word1")>0 or
find(var_1, "word2")>0 then got_value=1;
Is one way, but probably not optimal.
05-24-2013 12:49 PM
I looked up prx, but cannot get it to work. This sample I modified seems to be what I need, but it is not working:
if _N_ = 1 then
/* The i option specifies a case insensitive search. */
pattern = "/Mount|TGH|Joe|Michael|Sunny|Toro|Bay|Brid|Provi/i";
patternID = prxparse(pattern);
input service_provider $90.;
call prxsubstr(patternID, service_provider, position);
if position ^= 0 then
match = substr(service_provider, position);
put match:$QUOTE. "found in " service_provider:$QUOTE.;
05-30-2013 03:36 AM
We can try index or find but in huge datasets try not using If condition instead use where for faster application as in the following code;-
create table col_data as
select memname from
where index(upcase(memname),upcase("attribute"))>0; run;
05-24-2013 12:40 PM
You may want the FINDW, find word, function. And you can generally search for only one value at a time.
Also unless you are 100 percent positive that the words are always in the same case you may want to either UPCASE or LOWCASE the searched string and make sure the value searched for is in the same case.
findword1 = (findw(upcase(string), 'WORD')>0);
scan PULLS a word by position in a string.
05-24-2013 02:13 PM
PRX to the rescue!
length string $100;
input string &;
This is a sample text string
That is another string
And then a last string
/* Search string for :
a word boundary,
then the first string or the second string or ... or the last string,
then a word boundary
make the search case insensitive
compile the pattern only once */
set have(where=(prxmatch("/\b(this|now|then)\b/io", string)));
proc print noobs; run;