## Check the phone number is in ten digit?

Frequent Contributor
Posts: 114

# Check the phone number is in ten digit?

How to check the phone number is in ten digit?

if not,we need to move to error table.

how to do this?

Kindly help me.

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

Dear Helan,

Please share the sample data if avilable... r there any seperators or need to run for simple count...?

Sunil

Frequent Contributor
Posts: 114

## Re: Check the phone number is in ten digit?

Hi sunil,

My source data

Ph.No

9785474589

985745874

Need to check ph.no os in ten digit?

first row must go to target table.

second row must go to error table.

I ll try with Ksharp answer and let u knw.

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

data have;
input Ph_No  20.;
cards;
9785474589
985745874
98574587
;
run;

data target error;
set have;
if length(compress(Ph_No)) eq 10 then output target;
else output error;
run;

Frequent Contributor
Posts: 114

## Re: Check the phone number is in ten digit?

i tried with both the answer..

if the variable is char datatype,its working fine.

if it is in numeric datatype.its throwing error.

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

Hi, Please elaborate, since the solution shared was basis numeric values (best12. format).

Frequent Contributor
Posts: 114

## Re: Check the phone number is in ten digit?

Sorry sunil..I misunderstood tat...Its working fine.....

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

Good!!

Frequent Contributor
Posts: 114

## Re: Check the phone number is in ten digit?

Sunil,

I have some source data as

Ph.No

+919383434334

09547854854

919245485554

I need to load only ten characters in target.

What to do then?

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

data have;
input Ph_No 20.;
cards;
+919383434334
09547854854
919245485554
9785474589
985745874
98574587
;
run;

data target error;
set have;
Ph_No = substr(right(Ph_No),3);
if length(compress(Ph_No)) eq 10 then output target;
else output error;
run;

Frequent Contributor
Posts: 114

## Re: Check the phone number is in ten digit?

Sunil,

I didnt understand the exp.

substr(right(Ph_no),3)

what is that 3.

can u pls explain?

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

Healna,

Actually, The value for Ph_no is stored in numeric BEST12. Format, Hence starting from 3rd value till end will count 10 numeric as required by you.

Sunil

Contributor
Posts: 29

## Re: Check the phone number is in ten digit?

Helann, Oops I misspelled ur name..Sorry!!

Super User
Posts: 10,778

## Re: Check the phone number is in ten digit?

What does your data look like ?

```data right error;
input x : \$100.;
if prxmatch('/\d{10,10}/o',x) and length(x)=10 then output right;
else output error;
cards;
0000893220
0001193125
0000950129
000095012912
00009501291234
;
run;

```

Ksharp

Discussion stats
• 13 replies
• 411 views
• 0 likes
• 3 in conversation