BookmarkSubscribeRSS Feed
singhsahab
Lapis Lazuli | Level 10

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
Oligolas
Barite | Level 11

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 -

FreelanceReinh
Jade | Level 19

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).

Reeza
Super User
Please try and use more descriptive subject lines.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1974 views
  • 3 likes
  • 4 in conversation