for one thing if you want to put '/' in prxchange function, it has to be preceded by '\'. you can try this code.
data test;
text='102/103-Apple&Orange,';
text_new=prxchange('s/[,&\/-]/ /', -1, text);
proc print;
run;
for one thing if you want to put '/' in prxchange function, it has to be preceded by '\'. you can try this code.
data test;
text='102/103-Apple&Orange,';
text_new=prxchange('s/[,&\/-]/ /', -1, text);
proc print;
run;
Hello @Feyng819,
Why do you want to use a heavy tool for a simple task? For replacements of one character by another the TRANSLATE function is likely more efficient (and easier to work with) than PRXCHANGE:
Example:
31 data _null_; 32 c='102/103-Apple&Orange'; 33 c=translate(c, ' ', '/-&'); 34 put c; 35 run; 102 103 Apple Orange
The first character in the third argument is replaced by the first character in the second argument (here: a space). In the absence of more characters in the second argument, the remaining characters of the third argument are replaced with spaces by default. (So, even a zero-length string could be used as the second argument because of this default behavior.)
Also that I agree in principal with @FreelanceReinh one possible reason to use a RegEx here could be "laziness" in case you don't know all the characters in advance that you want to replace.
With RegEx metacharacters in expressions allow you to define whole sets.
Below code will replace any sequence of characters that aren't letters, digits or an underscore with a single blank.
data test;
text='102/103-Apple&+?Orange,';
/* ensure variable text_new has same length than text */
if 0 then text_new=text;
/* replace any sequence of characters that aren't alphanumeric or underscore with a blank */
text_new=prxchange('s/\W+/ /', -1, trim(text));
run;
proc print data=test;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.