- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 05-31-2021 09:22 AM
(2617 views)
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 !!
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please try and use more descriptive subject lines.