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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.