BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9
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


thank you for any help you can give me.
6 REPLIES 6
art297
Opal | Level 21
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
jerry898969
Pyrite | Level 9
Art,

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

Thank you
Jerry
sss
Fluorite | Level 6 sss
Fluorite | Level 6
Hi

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

by using conditional statement

WHERE COL2='%V%';
sss
Fluorite | Level 6 sss
Fluorite | Level 6
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
art297
Opal | Level 21
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
jerry898969
Pyrite | Level 9
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1147 views
  • 0 likes
  • 3 in conversation