Use an array.
See an example here:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001371428.htm
Something like this?
data have;
input Acct $ (col1-col3) ($);
cards;
ABC 45 375 89756
TFA 609 8320 835
FGT 5907 561 413
;
run;
data want;
set have;
array cols {*} col1-col3;
array newphone {*} $ newphone1-newphone3;
do i = 1 to 3;
newphone{i} = cats(put(length(cols{i}),z2.),cols{i});
end;
drop i;
run;
Some questions. Firstly, why are you trying to do this using text numbers? Numeric data types are there for a reason. Secondly, what is the reasoning behind this, newphone would end up looking like:
0245
03609
045907
Which doesn't really make sense to me. What is col1-col3, it looks from the var name newphone, to be a number, but catting on an 02/03 etc. wouldn't make the result a number. I mean you "could" do:
data have; input Acct $ col1 $ col2 $ col3 $; datalines; ABC 45 375 89756 TFA 609 8320 835 FGT 5907 561 413 ; run; data want; length newphone $20; set have; newphone=cats("0",put(lengthn(col1),best.),col1); run;
But why?
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.
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.