Check the phone number is in ten digit?

Reply
Frequent Contributor
Posts: 101

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?

Posted in reply to Helannivas

Dear Helan,

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

Sunil

Frequent Contributor
Posts: 101

Re: Check the phone number is in ten digit?

Posted in reply to sunilzood

Thnks for ur reply.

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?

Posted in reply to Helannivas

Please try:

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: 101

Re: Check the phone number is in ten digit?

Posted in reply to sunilzood


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?

Posted in reply to Helannivas

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

Frequent Contributor
Posts: 101

Re: Check the phone number is in ten digit?

Posted in reply to sunilzood

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

Contributor
Posts: 29

Re: Check the phone number is in ten digit?

Posted in reply to Helannivas

Good!!

Frequent Contributor
Posts: 101

Re: Check the phone number is in ten digit?

Posted in reply to sunilzood

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?

Posted in reply to Helannivas

* Please Try;

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: 101

Re: Check the phone number is in ten digit?

Posted in reply to sunilzood

Sunil,

I didnt get the answer...

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?

Posted in reply to Helannivas

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?

Posted in reply to sunilzood

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

Super User
Posts: 10,023

Re: Check the phone number is in ten digit?

Posted in reply to Helannivas

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

Ask a Question
Discussion stats
  • 13 replies
  • 362 views
  • 0 likes
  • 3 in conversation