SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kb011235
Obsidian | Level 7

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)

Perl Regular Expression (PRX) Metacharacters: Tables of Perl Regular Expression (PRX) Metacharacters...

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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.

View solution in original post

2 REPLIES 2
Reeza
Super User
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.

Tom
Super User Tom
Super User

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. . 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1232 views
  • 1 like
  • 3 in conversation