DATA Step, Macro, Functions and more

find the character in a string which is other than in the list

Reply
Contributor
Posts: 72

find the character in a string which is other than in the list

I am trying to find string which contains characters other than some set of characters. Is there any function available for that ?

 

for e.g.   I want to find strings in which there are characters which is other than a-z or A-Z or _. Any thing other than this would be caught.

Please help.

 

 

 

SAS Super FREQ
Posts: 709

Re: find the character in a string which is other than in the list

[ Edited ]
Posted in reply to anandbillava

Check the list of functions, specifically FINDC function

 

There are also functions for regular expressions, they start with PRX...

Contributor
Posts: 72

Re: find the character in a string which is other than in the list

Posted in reply to Bruno_SAS

Thank you Bruno. I tried to use prxmatch and findc. I am not able to suceed. I am trying to find characters which is not in the list which is making me difficult to achieve this. Its easy to find the characters in the list.

PROC Star
Posts: 7,492

Re: find the character in a string which is other than in the list

[ Edited ]
Posted in reply to anandbillava

There are a number of possibilities. 

 

The FINDC function, with the 'FK' modifiers, does exactly what you want. It's described at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002264923.htm

 

F includes A-Z, a-z and underscore in the list of characters and K sets the function to only find characters that AREN'T in that list of characters.

 

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 326

Re: find the character in a string which is other than in the list

[ Edited ]
Posted in reply to anandbillava

something like this

  data have;
      /* Use PRXPARSE to compile the Perl regular expression.    */
  
     val ='123abc';
	 output;
	 val ='bacde_bde';
	 output;
	 val='abcdef';
	 output;
	 val='abc-jj';
	 output;
run;

data want(drop=patternid);
set have;
 patternID = prxparse('/[^A-Za-z_]+/');
 if prxmatch(patternID, val)>0;
 run;
Contributor
Posts: 72

Re: find the character in a string which is other than in the list

Thank you all. I am able to do this using findc function.

Super User
Posts: 10,048

Re: find the character in a string which is other than in the list

data want;
set have;
 if prxmatch('/\W/', strip(val));
run;
Super User
Super User
Posts: 7,083

Re: find the character in a string which is other than in the list

Posted in reply to anandbillava

That is what the VERIFY() function does.

Ask a Question
Discussion stats
  • 7 replies
  • 159 views
  • 1 like
  • 6 in conversation