BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

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:

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0bj9p4401w3n9n1gmv6tf**bleep**9...

 

data want;
	set have;
	if prxmatch('/\d{10}/', Phone) then flag = 1;
	else flag = 0;
run;

Best,

 

Q1983
Lapis Lazuli | Level 10

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

Q1983
Lapis Lazuli | Level 10

cancel the last question, I will just redefine those affected phone numbers

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1061 views
  • 1 like
  • 2 in conversation