- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to match a phrase using the prxmatch function by passing it a column value.
data long_string;
infile datalines delimiter=',';
informat txt $40. keyp1 $20. keyp2 $20. keyp3 $20. keyp4 $20.;
input txt keyp1 keyp2 keyp3 keyp4;
datalines;
That is a great way to end the day,great way,end,today,even worse
;
run;
How can I go through the 4 keyp variables and match the phrase?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Well for one thing, the "o" pattern suffix instructs the matching function that the pattern is a constant, i.e. that it doesn't need to be recompiled at every invocation. Which is clearly not the case here.
BTW, the "i" suffix makes the matching case insensitive. So, no need for the lowcase() function call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This seems to work:
data first_try;
set long_string;
match1 = prxmatch(catt("m/(",lowcase(keyp1),")/oi"),txt);
match2 = prxmatch(catt("m/(",lowcase(keyp2),")/oi"),txt);
match3 = prxmatch(catt("m/(",lowcase(keyp3),")/oi"),txt);
match4 = prxmatch(catt("m/(",lowcase(keyp4),")/oi"),txt);
run;
I don't quite understand why my array is not working:
data final;
set long_string;
array keyp{4} $ keyp1-keyp4;
array match{4} match1-match4;
do i=1 to 4;
match[i] = prxmatch(catt("m/(",lowcase(keyp[i]),")/oi"),txt);
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Well for one thing, the "o" pattern suffix instructs the matching function that the pattern is a constant, i.e. that it doesn't need to be recompiled at every invocation. Which is clearly not the case here.
BTW, the "i" suffix makes the matching case insensitive. So, no need for the lowcase() function call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That fixed it, thank you for insight.