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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 672 views
  • 1 like
  • 3 in conversation