DATA Step, Macro, Functions and more

PERL Regular Expression Modifier

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

PERL Regular Expression Modifier

I have searched and not found the answer, hoping someone here can assist. The error message below is displayed in the SAS Log when I attempt to use the "/g" modifier in a prxparse statement.

ERROR: Regular expression option "g" in "/ABC-\d{4}-\d{4}/g" is not supported.

ERROR: The regular expression passed to the function PRXPARSE contains a syntax error.

 

It appears that "/g" is a valid PERL modifier however SAS does not support this modifier, so I need a solution that will allow me to find the patter above in a string and return all instances matched from the string, an example of the string is below.

"Technology Affected: program name here ABC ID: ABC-5102-2408 Record #:1596081 First publish date: 6/1/1969" or alternately

"Technology Affected: program name here ABC ID: ABC-5102-2408 ABC-9876-1234 ABC-7654-3456 ABC-0192-3948 Record #:1596081 First publish date: 6/1/1969"

 

Thank you in advance!

 


Accepted Solutions
Solution
‎08-10-2016 09:43 AM
Super User
Posts: 9,656

Re: PERL Regular Expression Modifier

And there is a little error in your PRX .

 

data _null_;
str="Technology Affected: program name here ABC ID: ABC-5102-2408 ABC-9876-1234 ABC-7654-3456 ABC-0192-3948 Record #:1596081 First publish date: 6/1/1969";
pid=prxparse('/ABC\-\d{4}\-\d{4}/o');
start=1;
stop=length(str);
call prxnext(pid,start,stop,str,p,l);
do while(p>0);
 temp=substr(str,p,l);
 call prxnext(pid,start,stop,str,p,l);
 put temp=;
end;
run;

View solution in original post


All Replies
Respected Advisor
Posts: 4,640

Re: PERL Regular Expression Modifier

What is modifier g supposed to  mean?

PG
Occasional Contributor
Posts: 19

Re: PERL Regular Expression Modifier

According to the help text on https://regex101.com/ the definition is:

"g modifier: global. All matches (don't return on first match)".

When i test my PERL expression on this site using the "g" modifier I get matches for all instances in the text example.

Respected Advisor
Posts: 4,640

Re: PERL Regular Expression Modifier

Look at CALL PRXNEXT() to retrieve multiple matches.

PG
PROC Star
Posts: 1,555

Re: PERL Regular Expression Modifier

 

SAS does not suport all perl modifiers. The only suffixes supported by sas are i x s m and o.

 

The documentation is wrong about what is supported though. For example \G is a supported assertion.

 

A full list of supported syntax together with examples is shown in

 

https://www.amazon.com/High-Performance-SAS-Coding-Christian-Graffeuille/dp/1512397490

 

 

Solution
‎08-10-2016 09:43 AM
Super User
Posts: 9,656

Re: PERL Regular Expression Modifier

And there is a little error in your PRX .

 

data _null_;
str="Technology Affected: program name here ABC ID: ABC-5102-2408 ABC-9876-1234 ABC-7654-3456 ABC-0192-3948 Record #:1596081 First publish date: 6/1/1969";
pid=prxparse('/ABC\-\d{4}\-\d{4}/o');
start=1;
stop=length(str);
call prxnext(pid,start,stop,str,p,l);
do while(p>0);
 temp=substr(str,p,l);
 call prxnext(pid,start,stop,str,p,l);
 put temp=;
end;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 318 views
  • 4 likes
  • 4 in conversation