BookmarkSubscribeRSS Feed
anandbillava
Fluorite | Level 6

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.

 

 

 

7 REPLIES 7
BrunoMueller
SAS Super FREQ

Check the list of functions, specifically FINDC function

 

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

anandbillava
Fluorite | Level 6

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.

art297
Opal | Level 21

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

 

kiranv_
Rhodochrosite | Level 12

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;
anandbillava
Fluorite | Level 6

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

Ksharp
Super User
data want;
set have;
 if prxmatch('/\W/', strip(val));
run;
Tom
Super User Tom
Super User

That is what the VERIFY() function does.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 7 replies
  • 1626 views
  • 1 like
  • 6 in conversation