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?
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.
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.
I updated the link.
https://support.sas.com/resources/papers/proceedings20/5172-2020.pdf this paper will go over a lot of it.
@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.
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_ ))?
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.