BookmarkSubscribeRSS Feed
SASSLICK001
Obsidian | Level 7

Hi All

 

I have a challenge to identify a particular pattern in the data, for example

 

AB, YZ

AB, AB, YZ

AB, AB, AB, YZ

...

 

if string AB comes before string YZ,  i need to identify these records, but AB can be any number of times (i.e. 1 to n) 

 

Any thoughts?

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

So in this example, all three records would be identified, correct?

Shmuel
Garnet | Level 18

Try to check by:

 

if scan(<variable namr>, -1, ' ,') = 'BZ' and  /* last string */

   scan(<variable namr>, -2, ' ,') = 'AB' 

  then ...; else ...;

PGStats
Opal | Level 21

Regular expressions are all about text patterns.

 

if prxMatch("/AB[, ]+YZ/i", string) then <do something>;

 

would match your example pattern. The pattern says: AB followed by one or more comma or a space characters, followed by YZ.

PG
Tom
Super User Tom
Super User

If it is really as simple as your example then no need for regular expressions.

index(string,'AB, YZ')

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1226 views
  • 0 likes
  • 5 in conversation