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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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