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??
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
Your REGEX is searching for periods, but your data has commas.
Where does it have commas? The variables have a space, and then a period.
Try
's/(\w+) \./\1./'
as the regular expression. \1 repeats the match from the first parenthesis.
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
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?
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;
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!
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.