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

Hi all,

 

I have a rather large dataset with two fields, phone1 and phone2. These are text based fields with up to 10 digit phone numbers, no special characters.

 

I'm looking for some ideas on how to set a flag field based on what could be a valid number, which is to say if the field is '0000000000', '4488888888', '999999', etc... I'd like to set a flag to mark it as potential unviable.

 

I've taken a stab at both proc sql (case statements) and data step (if/else) but I feel like I'm being inefficiant with my approach.

 

Any ideas?

 

Thanks in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You sure? I can't have a phone number that's 780-345-6789? I think the rules will need to be more clearly specified, etc isn't clear.

At any rate you'll be using a data step, and more than likely regex matching.
Googling "SAS Phone Number Validation" brought me to this page which is what I think you're looking for:

https://heuristically.wordpress.com/2012/10/30/phone-number-validation-in-sas/

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hi @Ody,

 

I think, before you start coding, you should write down specifications. Once you have a (preliminary) list of criteria (like "less than 5 digits", "more than 5 repetitions of the same digit", etc.), it will be fairly straightforward to program the corresponding IF conditions in a data step (maybe using the PRX functions). And many people in the forum will be able to support you.

 

PROC SQL will probably not come into play, unless you include criteria involving more than one observation at a time (like "more than 3 records have the same phone numbers").

Ody
Quartz | Level 8 Ody
Quartz | Level 8
Thanks for the input.

I'm looking to flag anything that isn't a phone number... so anything less than 10 digits that would exclude obvious non phone number type numbers (or characters in this case since the field is formatted as char). So that would include sequential numbers ascending/descending, repeating digits, etc...
Reeza
Super User
You sure? I can't have a phone number that's 780-345-6789? I think the rules will need to be more clearly specified, etc isn't clear.

At any rate you'll be using a data step, and more than likely regex matching.
Googling "SAS Phone Number Validation" brought me to this page which is what I think you're looking for:

https://heuristically.wordpress.com/2012/10/30/phone-number-validation-in-sas/
Ody
Quartz | Level 8 Ody
Quartz | Level 8

Wow, thanks for the link and feedback. Not sure why I didn't think of Googling that myself...

 

EDIT: The solution in the linked document worked beautifully. I made some modifications based on what I'm looking for but that gave me a great start. Thanks!!

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