BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ABprint
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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.

PG

View solution in original post

3 REPLIES 3
ABprint
Fluorite | Level 6

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;
PGStats
Opal | Level 21

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.

PG
ABprint
Fluorite | Level 6

That fixed it, thank you for insight. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 507 views
  • 0 likes
  • 2 in conversation