data have; length loan_number $10 ; input loan_number ; datalines; 2323333 22345099 112009899 345566 ; run; data have2; set have; ln_no=put(loan_number,z10.); run;
I ran the code and received format not found. Note this is a character variable. I want to assign leading zeros as needed to get a max 10 digit number in character format
Hi @Q1983 Yet another easy and lazy alternative-
data have;
length
loan_number $10
;
input loan_number ;
datalines;
2323333
22345099
112009899
345566
;
run;
data want;
set have;
length need $10;
need=translate(right(loan_number),'0',' ');
run;
Logic-
Move the contents to the right. Fill the blanks with 0.
In SAS there's always another way / different approach:
data have;
length
loan_number $10 ;
input loan_number ;
loan_number=substr("0000000000"||loan_number,length(loan_number)) ;
datalines;
2323333
22345099
112009899
345566
;
run;
Close.
data have;
input loan_number $10.;
put loan_number $10. ' -> ' @;
loan_number=substr("0000000000"||loan_number,1+lengthn(loan_number)) ;
put loan_number;
datalines;
1234567890
2323333
22345099
112009899
345566
;
-> 0000000000 1234567890 -> 1234567890 2323333 -> 0002323333 22345099 -> 0022345099 112009899 -> 0112009899 345566 -> 0000345566
Hi @Q1983 Yet another easy and lazy alternative-
data have;
length
loan_number $10
;
input loan_number ;
datalines;
2323333
22345099
112009899
345566
;
run;
data want;
set have;
length need $10;
need=translate(right(loan_number),'0',' ');
run;
Logic-
Move the contents to the right. Fill the blanks with 0.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.