DATA Step, Macro, Functions and more

%sysfunc(prxmatch())

Reply
Occasional Contributor
Posts: 14

%sysfunc(prxmatch())

Hi,
I was coding a macro and I decided to cut corners and use PRX on it.
But I found one detail that I could not understand (mind that i'm a newbie when it gets to macros and macro quoting Smiley Tongue).

My question is this:
why is that the folowing statements don't work or give incorrect results:
%put %sysfunc(prxmatch(/\d/,123));
%put %sysfunc(prxmatch('/\d/',123));
%put %sysfunc(prxmatch(%nrbquote(/\d/),123));
%put %sysfunc(prxmatch(%nrbquote('/\d/'),123));

the only way I got it to work was:
%put %sysfunc(prxmatch(%nrbquote('\d'),123));


Can anyone explain this to me??


Thanks in advance
Pedro Glória
Super Contributor
Super Contributor
Posts: 3,174

Re: %sysfunc(prxmatch())

How about a reply to explain in non-PRX language-speak, what it is you want to accomplish? Suggest a BEFORE and AFTER data-string, if you would -- there may be other options to you, not involving PRX.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 14

Re: %sysfunc(prxmatch())

These examples are just a reduction of my problem, on those examples I want each line to output 1 to the log.

I just realy want to understand the reason for me not getting to use the slash '/' on the regex when I use the PRX functions inside a %sysfunc.

On the last of my examples I got it working, so it's just to kill my curiosity.


Thanks Smiley Wink
Occasional Contributor
Posts: 14

Re: %sysfunc(prxmatch())

Found the problem,
The prxmatch function has 2 versions one that gets a regular-expression-id and the other a perl-regular-expression has the firt parameter.

SAS checks the first char in the string, and if it is a number or a aritmetic operator it %evals() the parameter.

So, doing:
%let regex_id=%sysfunc(prxparse(/\d/));
%put %sysfunc(prxmatch(&regex_id,123));

Works like a charm Smiley Wink
Ask a Question
Discussion stats
  • 3 replies
  • 719 views
  • 0 likes
  • 2 in conversation