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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3802 views
  • 3 likes
  • 2 in conversation