DATA Step, Macro, Functions and more

Processing fields based on value(s)

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 83
Accepted Solution

Processing fields based on value(s)

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.

 

 


Accepted Solutions
Solution
‎12-01-2015 12:36 PM
Super User
Posts: 19,767

Re: Processing fields based on value(s)

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


All Replies
Trusted Advisor
Posts: 1,117

Re: Processing fields based on value(s)

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").

Frequent Contributor
Frequent Contributor
Posts: 83

Re: Processing fields based on value(s)

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...
Solution
‎12-01-2015 12:36 PM
Super User
Posts: 19,767

Re: Processing fields based on value(s)

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/
Frequent Contributor
Frequent Contributor
Posts: 83

Re: Processing fields based on value(s)

[ Edited ]

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 286 views
  • 0 likes
  • 3 in conversation