BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pdhokriya
Pyrite | Level 9

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*/

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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;
SASKiwi
PROC Star
proc sql;
select put(input(customer_id, 6.), z6.) as customer_id_new length = 6
from have;
quit;
pdhokriya
Pyrite | Level 9
THis is not working
Ksharp
Super User
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1021 views
  • 5 likes
  • 4 in conversation