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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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