DATA Step, Macro, Functions and more

Phone Number Help

Reply
N/A
Posts: 0

Phone Number Help

I have phone number data in which the three “parts” of the phone number were originally stored as separate numeric variables so that any leading zeroes were dropped (e.g., “014” became 14 and “004” became 4. So a phone number of 004-017-0123 is now shown as 4-17-123.)

How can I re-seperate the numbers and re-add the dropped zeros?

Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: Phone Number Help

In a DATA step, use the SCAN function to split the data-string into three, and also use the PUT(,Z3.) for example. And use CATX to rebuild the number from the components.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Phone Number Help

Thanks Scott, almost there. When I use CATX to reform the phone numbers after splitting and adding the zeros, CATX drops off the zeros I added. Any ideas? My current code is below. Thanks.

Phone_Number=Translate(Phone_Number,'---','._/');

format Phone1 Phone2 z3. Phone3 z4.;
Phone1=scan(Phone_Number,1);
Phone2=scan(Phone_Number,2);
Phone3=scan(Phone_Number,3);

PhoneCorrect=catx('-',Phone1,Phone2,Phone3);
Frequent Contributor
Posts: 81

Re: Phone Number Help

Phone1=input(scan(Phone_Number,1),best.);
Phone2=input(scan(Phone_Number,2),best.);
Phone3=input(scan(Phone_Number,3),best.);
PhoneCorrect=catx('-',put(Phone1,z3.),put(Phone2,z3.),put(Phone3,z4.));
Valued Guide
Posts: 2,174

Re: Phone Number Help

change the parameters of catx() so they are strings not numerics - you were getting automatic numeric-to-character conversion

PhoneCorrect=catx('-', put(Phone1,z3.), put(Phone2,z3.), put(Phone3,z4.));
N/A
Posts: 0

Re: Phone Number Help

Thanks everyone. Things are looking great now.
Ask a Question
Discussion stats
  • 5 replies
  • 178 views
  • 0 likes
  • 4 in conversation