BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chrisas
Fluorite | Level 6

Hi everyone!

 

I would like to extract all the strings with a specific format for example "ABCxxx_x". 

 

The 'x' symbol refers to digit numbers (from 0 to 9).

 

For example, I want to get the string "ABC123_3" or "ABC598_4".

 

Could anyone help me?

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

Here's an example using PRXMATCH 
I made some assumptions, but the example should help

 

data have ;
	infile cards ;
	input myText :$12. ;

cards;
ABC123_4
DEF567_8
not_me
or_me
or_123
;

data want ;
	retain patternID;
	if _n_=1 then do ;
      pattern="/[A-Z]{3}[0-9]{3}_[0-9]/";
      patternID=prxparse(pattern);		
	end ;
	set have ;
	position=prxmatch(patternID, myText);
	put mytext= @25 position= ;
run ;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

So you want all strings that begin with "ABC"? Or all strings that begin with any three letters followed by numbers and/or symbols? Or can strings that begin with 2 characters or 4 characters also be acceptable? 

 

Don't make us generalize from a single example, that is impossible.


Please explain exactly what you are looking for. Give examples of what you want and what you don't want.

--
Paige Miller
Chrisas
Fluorite | Level 6
Thank you for your response. I want the first three letters to begin with "ABC" then the next three characters to be digit number from 0-9, then underscore and then one digit number from 0-9.

For example: I want ABC123_3 or ABC564_9.
andreas_lds
Jade | Level 19

We need to know how the strings look it and what you expect as result., so please provide data in usable form and show what you want.

AMSAS
SAS Super FREQ

Here's an example using PRXMATCH 
I made some assumptions, but the example should help

 

data have ;
	infile cards ;
	input myText :$12. ;

cards;
ABC123_4
DEF567_8
not_me
or_me
or_123
;

data want ;
	retain patternID;
	if _n_=1 then do ;
      pattern="/[A-Z]{3}[0-9]{3}_[0-9]/";
      patternID=prxparse(pattern);		
	end ;
	set have ;
	position=prxmatch(patternID, myText);
	put mytext= @25 position= ;
run ;

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
  • 5 replies
  • 965 views
  • 1 like
  • 5 in conversation