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-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!

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.

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