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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.