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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.