BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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);
NickR
Quartz | Level 8
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.));
Peter_C
Rhodochrosite | Level 12
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.));
deleted_user
Not applicable
Thanks everyone. Things are looking great now.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 865 views
  • 0 likes
  • 4 in conversation