It appears to me that there is an error when using prxmatch with SAS DS2. It is also possible my code is in error. I want to know if this problem is because of my code or a compile error with SAS.
In the code below I match search terms in one data table with search text in another.
data master_table;
input name $ search_text $;
datalines;
Frank allHere
John Sales
Mary Acctng
Joe Findme
Sue Hereiam
Jim graccaa
;
run;
proc print data= master_table; run;
data search_term_table;
infile datalines missover;
input id $ search_term $;
datalines;
1 Here
2 Find
3 Acc
;
run;
proc ds2;
data search_results (overwrite=yes);
retain rc;
dcl double rc c ;
declare char(8) id N;
declare char(11) name;
declare char(1) c_options;
declare char(20) search_term search_text;
dcl package hash h(1, 'search_term_table');
dcl package hiter hi('h');
method init();
rc = h.keys([id]);
rc = h.data([id search_term]);
rc = h.defineDone();
end;
method run();
dcl double rc;
set master_table;
if _N_ = 1 then put 'ROW ITEM';
N = _N_;
rc = hi.first();
do while(rc=0);
c_options = 'i';
search_term = cats('/', search_term, '/', c_options);
search_text = catx(' ', search_text);
c = prxmatch(search_term, search_text);
put N id 'prxmatch(' search_term ',' search_text '); ---> ' c;
output;
rc = hi.next();
end;
end;
enddata;
run;
quit;
The results of the put statement are shown below.
In ROW 3
ITEM 1
a match is incorrectly found, because it is using the regex from the last item of the previous row, not the current one.
In ROW 5
ITEM 1
the situation is reversed. A match is not found because, again, it is using the regex from the last item of the previous row.
ROW ITEM
1 1 prxmatch( /Here/i , allHere ); ---> 4
1 2 prxmatch( /Find/i , allHere ); ---> 0
1 3 prxmatch( /Acc/i , allHere ); ---> 0
2 1 prxmatch( /Here/i , Sales ); ---> 0
2 2 prxmatch( /Find/i , Sales ); ---> 0
2 3 prxmatch( /Acc/i , Sales ); ---> 0
3 1 prxmatch( /Here/i , Acctng ); ---> 1
3 2 prxmatch( /Find/i , Acctng ); ---> 0
3 3 prxmatch( /Acc/i , Acctng ); ---> 1
4 1 prxmatch( /Here/i , Findme ); ---> 0
4 2 prxmatch( /Find/i , Findme ); ---> 1
4 3 prxmatch( /Acc/i , Findme ); ---> 0
5 1 prxmatch( /Here/i , Hereiam ); ---> 0
5 2 prxmatch( /Find/i , Hereiam ); ---> 0
5 3 prxmatch( /Acc/i , Hereiam ); ---> 0
6 1 prxmatch( /Here/i , graccaa ); ---> 3
6 2 prxmatch( /Find/i , graccaa ); ---> 0
6 3 prxmatch( /Acc/i , graccaa ); ---> 3
NOTE: Execution succeeded. 18 rows affected.
2752 quit;