data have;
input Phone $15.;
datalines;
0000000000
0
1111111111
2222222222
8391134456
;
run;
I have a dataset that presents phone numbers as a character variable which is common. If the phone number is a blank, a 0 or some other incomplete phone number I want to flag it. So in the above example the last transaction is an actual phone number that can be called. The others are not. In this example I using just a few examples however the phone field could show any combination of incomplete phone numbers. Should this be done through something like proc format or is there another way
Hi @Q1983,
You can use the PRXMATCH function to do this job.
This function checks whether a variable matches a specified pattern.
According to your description, I assume that the condition to be considered as a valid phone number is to have 10 digits.
If this is right, you can specify the following pattern (= look for 10 digits). Otherwise, you need to specify the rules (e.g. to have the 3 first digits in let's say 2-8, ...). For further information about this function:
data want;
set have;
if prxmatch('/\d{10}/', Phone) then flag = 1;
else flag = 0;
run;
Best,
Thanks for the post. If I see a number like 1111111111, 2222222222 etc, these are not valid phone number because you cannot call those numbers. Your code does satisfy the 9 digit format requirement. Is there a way to modify the code to address the above issue??
cancel the last question, I will just redefine those affected phone numbers
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.