Hi Reader,
I have to add leading zero in alpha numberic data. Also I am sharing my code mentioned below as I am not statisfied with the solution.
So is there any function/call/macro where i can get "customer_id_new" data ?
Thank you in Advance.Take care!
/***********************************/
data test;
length customer_id $ 6;
infile datalines;
input customer_id;
datalines;
2
10
467
8759
23490
341234
A
A2
A33
A444
A5555
A66666
;
run;
proc sql;
select
(case
when length(customer_id) = 6 then customer_id
else repeat('0',6-length(customer_id)-1)||customer_id
end)
as customer_id_new length 6
from test;
run;
/*Program End*/
data test; length customer_id $ 6; infile datalines; input customer_id; new=translate(right(customer_id),'0',' '); datalines; 2 10 467 8759 23490 341234 A A2 A33 A444 A5555 A66666 ; run;
Using a data-step:
data want;
set test;
length newID $ 6;
newID = repeat('0', 5);
substr(NewID, 6-lengthn(customer_id)+1) = trim(customer_ID);
run;
proc sql;
select put(input(customer_id, 6.), z6.) as customer_id_new length = 6
from have;
quit;
data test; length customer_id $ 6; infile datalines; input customer_id; new=translate(right(customer_id),'0',' '); datalines; 2 10 467 8759 23490 341234 A A2 A33 A444 A5555 A66666 ; run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.