BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stataq
Obsidian | Level 7

Hello,

 

I am new to regular expression and feel lost when I try to understand the pattern that are described in this format.

 

I see a follwoing codes  and could not understand what they means. Could anyone guide me on this?Thanks.

 

footnote( _n_ ) ne " "
and prxmatch( "/^'\s*'$/" , strip( footnote( _n_ ))) = 0
and prxmatch( '/^"\s*"$/' , strip( footnote( _n_ ))) = 0
and resolve( footnote( _n_ )) ne " "
and prxmatch( "/^'\s*'$/" , strip( resolve( footnote( _n_ )))) = 0
and prxmatch( '/^"\s*"$/' , strip( resolve( footnote( _n_ )))) = 0

 

what "prxmatch( "/^'\s*'$/" , strip( footnote( _n_ ))) = 0" mean? 

whether it is same as " prxmatch( '/^"\s*"$/' , strip( footnote( _n_ ))) = 0"?

why we need "resolve( footnote( _n_ )) ne " "" and then repeat prxmatch process?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You need to pass the RegEx as a string to the SAS RegEx function. That's why you need the outer quotes. The can be single or double quotes.

 "/^'\s*'$/"

 

To not get into some complicated masking exercise the inner quotes must just be different from the outer quotes (if outer single then inner double and vise versa). 

The inner quotes are now just part of the Regular Expression - which I assume is not what the developer intended to do.

 

The RegEx is: ^'\s*'$

^ Beginning of string

' the single quote character

\s a non-printable character , 

* zero, one or many occurrences of the previous character -> zero, one or many non-printable characters

' the single quote character

$ end of string

 

Above RegEx will find a match if the source string only contains zero, one or multiple non-print characters that are embedded into single quotes. If there is any other character in the string then it won't be a match (because of ^'...'$).

 

Because SAS is padding character variables with blanks what's also really important is to use trim() or strip() around the source variable to search.

View solution in original post

8 REPLIES 8
tarheel13
Rhodochrosite | Level 12

refer to the documentation.https://documentation.sas.com/doc/en/vdmmlcdc/8.1/ds2ref/p0m49np18q0pdxn1laab98pazajo.htm

It will return 0 if no match is found. 

stataq
Obsidian | Level 7
Only got "Page not found" with refence link. 😅

Do you know what "/^'\s*'$/" means? Thanks.
tarheel13
Rhodochrosite | Level 12
Just search PRXMATCH in SAS documentation. There are also plenty of papers on prxmatch on lexjansen.com. ^ means the beginning of the string. \s is whitespace. $ is the end of the string. You really need to read the documentation to understand the PRXMATCH function. Every good programmer must look into the documentation for things they don’t know.
tarheel13
Rhodochrosite | Level 12

I updated the link. 

Patrick
Opal | Level 21

@stataq This syntax doesn't look right to start with because of the quoting.

SAS functions that start with prx.. like prxmatch() allow to use Perl Regular Expressions within SAS code. 

Regular Expressions can be very powerful for working with text patterns.

Learning the Perl Regular Expression syntax will take you a bit of time. Others already shared links with you to get into it.

stataq
Obsidian | Level 7

Thanks for the input.

Do you mean two ' in "/^'\s*'$/" should not be allowed? I did have difficulty understand why there are ' ' in the code and the next line they have " ". In my mind, even the first one is correct, ''="" in most of the place, why there are two lines? what is the benefit to do repeat this process on resolve( footnote( _n_ ))?

Patrick
Opal | Level 21

You need to pass the RegEx as a string to the SAS RegEx function. That's why you need the outer quotes. The can be single or double quotes.

 "/^'\s*'$/"

 

To not get into some complicated masking exercise the inner quotes must just be different from the outer quotes (if outer single then inner double and vise versa). 

The inner quotes are now just part of the Regular Expression - which I assume is not what the developer intended to do.

 

The RegEx is: ^'\s*'$

^ Beginning of string

' the single quote character

\s a non-printable character , 

* zero, one or many occurrences of the previous character -> zero, one or many non-printable characters

' the single quote character

$ end of string

 

Above RegEx will find a match if the source string only contains zero, one or multiple non-print characters that are embedded into single quotes. If there is any other character in the string then it won't be a match (because of ^'...'$).

 

Because SAS is padding character variables with blanks what's also really important is to use trim() or strip() around the source variable to search.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 671 views
  • 3 likes
  • 3 in conversation