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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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