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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1749 views
  • 3 likes
  • 4 in conversation