## Searching a pattern

Super Contributor
Posts: 405

# Searching a pattern

I have a situation where I need to search a character column for a specific pattern. The pattern is based on type. I need to search within a string for a number then a capital "V" then another number right next to it.

For example within this list below I want all the rows returned except the last one.
Test 1V4
Test 1V9
Test 1V3
Test 222

PROC Star
Posts: 8,165

## Re: Searching a pattern

Jerry,

You may have to be more specific regarding what you are looking for. The following will find a pattern of a number, followed by the letter V, followed by a number, anywhere in a string:
[pre]
data have;
informat string \$20.;
input string &;
cards;
Test 1V4
Test 1V9
Test 1V3
Test 222
Test 22V
Test 3V5
;

data want;
set have;
if _n_ = 1 THEN pattern_loc = PRXPARSE("/\d\V\d/");
*Exact match for number, followed by the letter V, followed by
a number anywhere in the string;
retain pattern_loc;
position=prxmatch(pattern_loc,string);
run;
[/pre]
Of course, if what you really want deviates from that, in any way, a different prxparse call would have to be written. You can find a nice introductory article on pattern matching at: http://www.nesug.org/proceedings/nesug03/bt/bt002.pdf

HTH,
Art
Super Contributor
Posts: 405

## Re: Searching a pattern

Art,

Thank you so much that was it. I was looking for a number then the letter "V" then another number.

Thank you
Jerry
Contributor
Posts: 65

## Re: Searching a pattern

Hi

U can use this logic in either data step or proc step

by using conditional statement

WHERE COL2='%V%';
Contributor
Posts: 65

## Re: Searching a pattern

Hi
ignore previous one

U can use this logic in either data step or proc step

by using conditional statement

WHERE string like '%V%'; Message was edited by: sss
PROC Star
Posts: 8,165

## Re: Searching a pattern

I prefer regular expressions to precisely identify what one needs to match. Your code will accept any value that contains a letter V, regardless of what (if anything) comes before or after it.

> Hi
> ignore previous one
>
> U can use this logic in either data step or proc
> step
>
> by using conditional statement
>
> WHERE string like '%V%';
>
> Message was edited by: sss
Super Contributor
Posts: 405

## Re: Searching a pattern

sss,

Thank you for your reply as well. That won't work because there can be other "V" in the string. I need the number "V" number pattern.

Thank you for the suggestion

Jerry
Discussion stats
• 6 replies
• 165 views
• 0 likes
• 3 in conversation