I want to replicate this using PCRXFIND instead of prxmatch for speed and because prxmatch is not working correctly.
I am trying to find text in a data file. Here is a reproducible example. There is one file with the data to search and another with the search terms. I want to use regular expressions. Normally this is done with prxmatch. I want to do it with PCRXFIND because I am working inside DS2. I use a hash iterator to iterate through the search terms or each observation in the data set.
The search result do not follow any pattern I can recognize. I would be happy for any suggestions. I posted this on sas communities with not results.
* ds2 PCRXFIND example;
data person;
input name $ dept $;
datalines;
John Sales
Mary Acctng
Joe Findme
Sue Hereiam
;
run;
data searchterms;
infile datalines missover;
input s_index $ term $;
datalines;
1 Hereiam
2 Findme
3 Acc
;
run;
proc contents data=searchterms; run;
proc print data=searchterms; run;
proc ds2;
data search_results (overwrite=yes);
dcl double rc c ;
declare char(8) s_index;
declare char(8) term;
declare char(11) name dept;
declare char(1) c_options;
declare char(20) search_term search_text;
dcl package hash h(1, '{select s_index, term from searchterms}');
dcl package hiter hi('h');
method init();
c_options = 'i';
rc = h.defineKey('s_index');
rc = h.defineData('term');
rc = h.defineDone();
end;
method run();
dcl double rc;
set {select name, dept from person};
rc = hi.first();
do while(rc=0);
c = prxmatch('/'||compress(term)||'/i',name||' '||dept);
search_term = '/'||compress(term)||'/i';
search_text = name||' '||dept;
rc = hi.next();
output;
end;
end;
enddata;
run;
quit;