I want to replicate this using PCRXFIND instead of prxmatch for speed and because prxmatch is not working correctly.
I expect the following to match and I want the code to use PCRXFIND not prxmatch.
John Sales Mary Acctng Act Joe Findme Findme Sue Hereiam Hereiam
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.
* 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;
"and because prxmatch is not working correctly." - can you explain this? Never had any problems with prxmatch as long as I used trim on the second argument.
If you run the code I posted, the matched lines don't correspond to the search terms. I save the search terms in the data set and it is clear I don't need the trim the second term. But I never trim the string to be searched (second term). Sometimes I trim the search term (first term).
Perhaps it would help to show what you expect or desire to see given that example data.
Ok, I made that more explicit. I want the solution to use PCRXFIND.
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!
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.