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

I have a long list of patterns that I need to check to see if there are matches in my data.
Which function do you recommend that would be the quickest to create code for checking for a long list of patterns?
Types of patterns I'm interested in matching are:
122Y[digit 0-9]P68A
12811[digit 0-9][digit 0-9]E
13559[digit 0-9][digit 0-9]
65G101[digit 0-9][digit 0-9]
F6364[digit 0-9][digit 0-9]-66[letter A-Z]

 

Thank you.

1 ACCEPTED SOLUTION
3 REPLIES 3
gzr2mz39
Quartz | Level 8

Thank you. This macro seems to work well.

Do you have any more advice with regards to using regex functions with a long list of patterns?

In addition to creating a long list of patterns to check, the list of values I'm checking for these patterns is >700,000.

Any advice for improving efficiency would be appreciated.

%macro prx(pattern);
b=prxparse("&pattern");
if prxmatch(b,serial_number)>0 then check=1;
%mend;

%prx(/^2C1522[\d][\d]$/);

 

Thank you.

Reeza
Super User

I'm not that familiar with regex so I would suggest reposting this specifically and asking for efficiency, if you already have not. 

 

There is a way to speed it up so that SAS is not resolving the prx every time but I don't know enough to illustrate it. 

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!

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