SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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