Hi, a program I inherited has this operation:
prxchange('s/\W//',-1, string)
I'm having trouble deciphering the metacharacters, 's/\W//'.
When I ran the program and compared the strings before and after the operation, there were no differences, so whatever text it's meant to fix doesn't exist in any of the strings. However, I still need to know what it does. I was able to understand part of it using the following links:
Functions and CALL Routines: Using Perl Regular Expressions in the DATA Step - 9.2 (sas.com)
s/ |
specifies a substitution regular expression. |
\W | matches any non-word character or nonalphanumeric character, and excludes the underscore. |
Are the last two // the pattern for which it's searching? (Though not part of the question, for completeness, the -1 specifies that matching patterns continue to be replaced until the end of the source is reached.)
Thanks
data have;
input string $10.;
newString = prxchange('s/\W//',-1, string);
cards;
ABCD1233
ADF343
A?32!
ABC-45
ABC_$%98
;;;;
run;
Removes any : non-word character or nonalphanumeric character, and excludes the underscore.
data have;
input string $10.;
newString = prxchange('s/\W//',-1, string);
cards;
ABCD1233
ADF343
A?32!
ABC-45
ABC_$%98
;;;;
run;
Removes any : non-word character or nonalphanumeric character, and excludes the underscore.
Your first is incomplete. s/ is just the START of the substitution. The second slash ends the search pattern and the third slash ends the replacement pattern. .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.