Some of my variables have a space before the period, like this:
word .word
word .wordI would like them to look like this:
word.word
word.wordI'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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.