Hi All,
I'm trying identified all special char present in string expect Keyboard character.
Below is my program, which is not working for '%$' characters. Please help me how i can ignore '%$' and " as well.
DATA WANT;
STRING="AD'GADJ%$'123@~`";
Identified_Specialcharacters = prxchange('s/[a-z A-Z 0-9 .,?#()-~`!@#^&*_+={}[]|\?><:;%]//i',-1,STRING);
RUN;
Thank you in Advance !!
Hi,
you need to escape with backslash each of the metacharacters
{}[]()^$.|*+?\
DATA WANT;
length regEx EscIgnoreChars $200 string $3000;
STRING='β∞∞π';
EscIgnoreChars=translate(trim(' { } [ ] ( ) ^ $ . | * + ? \'),'\',' ');
regEx=cats('s/','[','\w',EscIgnoreChars,',#-~`!@&_=><:;%',']','//i');
put regex=;
Identified_Specialcharacters = cats('>>',prxchange(regEx,-1,STRING),'<<');
if Identified_Specialcharacters ne '>><<' then put 'E' 'RROR:' Identified_Specialcharacters=;
RUN;
Make sure you run SAS with unicode Support to be able to display any of the special chars.
- Cheers -
Hi @singhsahab,
On an ASCII system you can also specify a range of hexadecimal ASCII codes:
prxchange('s/[\x20-\x7E]//',-1,STRING)
As far as I see, this range consists of all characters you want to remove plus the forward slash ('/' = '2F'x).
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.