BookmarkSubscribeRSS Feed
gyambqt
Obsidian | Level 7

Hi Experts,

 

I have a list of phone number that including both Australia and oversea. the length of the phone number is undefined (can be anything)

 

I want to know if there is a smart way to find repeated pattern within any phone number without using regular expression. 

 

for example:   04123123123 has repeated pattern 123123123

 

or 1212121212

has repeated pattern 1212121212 

 

thanks

6 REPLIES 6
Patrick
Opal | Level 21

And why don't you want to use RegEx as that's the "ideal" syntax for anything pattern?

Astounding
PROC Star

Do the repetitions have to be consecutive, or could this be a repeating pattern:  1234123

 

Could a repeating pattern contain as few as four digits (the original two, plus one repetition)?

gyambqt
Obsidian | Level 7
Yes it can has repeats like that . But I want to remove the one that obviously invalid phone number.
Astounding
PROC Star

Well, it's not really clear what "obvious" means in this context.  So here's an example of how to do this for three-digit sets of digits:

 

length repeated3 $ 3;

if length(phoneno) >= 6 then do k=1 to length(phoneno)-5;

   repeated3 = substr(phoneno, k);

   if index( substr(phoneno, k+3), repeated3) then output;

end;

 

  

gyambqt
Obsidian | Level 7
Hi Patrick, I thought there might be some mathematic tricks like 12121212 is divisible by 10101 that able to solve the issue.
Patrick
Opal | Level 21

@gyambqt wrote:
Hi Patrick, I thought there might be some mathematic tricks like 12121212 is divisible by 10101 that able to solve the issue.

May be. But especially because this is about the very common case of phone number validation I'd go for RegEx. There should be a lot of RegEx published on the Internet and you won't have to "invent" everything from scratch. Just search a bit and use the one closest to your needs as a starting point.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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