- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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. .