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

Hi all,

 

I would like to do the following searching in my sample test dataset.

 

1.  Searching 4 numbers + 2 letters afterwards

2.  Searching any numbers starting with 000. 

 

The result I am looking for is in the Find column.

 

data Text;
      infile datalines dsd;
  input TempID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.   Find :  $10. ;
datalines;
1156 IL, 89__46, 88--53, , , 1156IL
1487-KM, __8956, _78-52__, Car 4632, , 1487KM
000-597, -1596_, 4113, , ,  000597
C_ _-1156, 4986__, 0_0-0_8, , , 0008
208, 8M _ O23, , , Car ID 7788 GH, 7788GH
HB_21156--, 89   66, 885 - 2, 5 5 5 9, 0056,  
;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

%* Finds 4 digits, then an optional non-word character, then 2 letters;

POS1 = prxmatch('/\d{4}\W?[a-zA-Z]{2]/' , TEMP_ID);

 

%* Finds 3 zeros then a series of one or more digit(s);

POS2 = prxmatch('/000\d+/' , TEMP_ID);       

 

What do you do once you find these?

 

View solution in original post

4 REPLIES 4
Reeza
Super User
Symbols don't seem to matter between the numbers/character? Is it only underscore and hyphen and spaces or are there possibly other separators that need to be ignored?
ChrisNZ
Tourmaline | Level 20

Like this?

%* Finds 4 digits, then an optional non-word character, then 2 letters;

POS1 = prxmatch('/\d{4}\W?[a-zA-Z]{2]/' , TEMP_ID);

 

%* Finds 3 zeros then a series of one or more digit(s);

POS2 = prxmatch('/000\d+/' , TEMP_ID);       

 

What do you do once you find these?

 

andreas_lds
Jade | Level 19

@ybz12003 The values in Find are not according with the description you have posted, please fix it.

ybz12003
Rhodochrosite | Level 12

Don't worry about it, I found the solution myself.  Thanks for your help!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1318 views
  • 0 likes
  • 4 in conversation