BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Caetreviop543
Obsidian | Level 7

Some of my variables have a space before the period, like this:

 

word .word
word .word

I would like them to look like this:

word.word
word.word

I'm trying to use prxchange, but it's not working. 

 

prxchange('s/ \w+ \./\w+\./', -1, variable);

What am I doing wrong??

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11

If your are trying to remove a single space followed by a "." try :

 

data _null_;

want = prxchange('s/\s././', -1, "word .word");

put want =;
run;

 

26         data _null_;
27         
28         want = prxchange('s/\s././', -1, "word .word");
29         
30         put want =;
31         run;

want=word.word

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

Your REGEX is searching for periods, but your data has commas.

Caetreviop543
Obsidian | Level 7

Where does it have commas? The variables have a space, and then a period.

PGStats
Opal | Level 21

Try

 

's/(\w+) \./\1./'

 

as the regular expression. \1 repeats the match from the first parenthesis.

PG
r_behata
Barite | Level 11

If your are trying to remove a single space followed by a "." try :

 

data _null_;

want = prxchange('s/\s././', -1, "word .word");

put want =;
run;

 

26         data _null_;
27         
28         want = prxchange('s/\s././', -1, "word .word");
29         
30         put want =;
31         run;

want=word.word
Caetreviop543
Obsidian | Level 7

Thanks! Is the \ before the period to denote meta characters, only required for the first argument ('s/first argument/second argument', -1, variable) in prxchange?

novinosrin
Tourmaline | Level 20

For what it's worth, here is my stab at it

 

data have;
input var $20.;
cards;
word .word
word .word
;

data want;
 set have;
 want=prxchange('s/(\w+)\s\.(\w+)/$1.$2/', -1, var);
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 1004 views
  • 4 likes
  • 5 in conversation