BookmarkSubscribeRSS Feed
Pgloria
Obsidian | Level 7
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 :p).

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
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Pgloria
Obsidian | Level 7
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 😉
Pgloria
Obsidian | Level 7
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 😉

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4647 views
  • 3 likes
  • 2 in conversation