Dear all,
How can I find all the special characters? and split the special character in a new variable?
for example
for JUICE∫app$le,
I expect to get
| old | special | new |
| JUICE∫app$le | ∫ | JUICE app le |
| JUICE∫app$le | $ | JUICE app le |
data have ;
infile datalines truncover;
input name $100.;
datalines;
JUICE∫app$le
juice <BR> apple
juice, 'apple'
juice{BODY} ap¶ple
[BR]juice apple
<figure> "juice" LTD
;
run;
(Special characters are characters that are not part of the following set of letters, digits and punctuation characters: A-Z; 0-9; “-“; “+”; “’”; “””; “#”; “*”; “@”; “!”; “?”; “/”; “&”; “(“; “)”; “:”; “;”; “,”; “.”; “ “.)
Could you please give me some suggestions about this?
thanks in advance
data want;
format old special new;
set have;
RegExID = prxparse('/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/');
start=1;
call prxnext(RegExID, start, length(old), old, pos, length);
new=prxchange('s/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/ /', -1, old);
do while (pos > 0);
special = substr(old, pos, length);
output;
call prxnext(RegExID, start, length(old), old, pos, length);
end;
keep old special new;
run;
You could use the FINDC function, with modifiers "A", "K", "D", and the character list would be the punctuation you don't want to find as shown in your message.
You could use compress function twice to get both strings. Try:
data want;
set have;
length special new $ 100 specialChars $ 20;
retain specialChars;
drop specialChars;
if _N_ = 1 then do;
specialChars = cat('-+#*@!?/&():;,. "', "'");
end;
special = compress(name, specialChars, 'adik');
new = compress(name, specialChars, 'adi');
run;
data want;
format old special new;
set have;
RegExID = prxparse('/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/');
start=1;
call prxnext(RegExID, start, length(old), old, pos, length);
new=prxchange('s/[^A-Z|a-z|0-9|-|\+|’|”|#|\*|@|!|\?|\/|&|\(|\)|:|;|,|.]/ /', -1, old);
do while (pos > 0);
special = substr(old, pos, length);
output;
call prxnext(RegExID, start, length(old), old, pos, length);
end;
keep old special new;
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.