DATA Step, Macro, Functions and more

Leading 0

Reply
Super Contributor
Posts: 673

Leading 0

There is a column that has values mix of Alphabets and numbers. I need to append a leading 0 if there only a single digit as shown below:

ColumA

MV

ZX

5

12

The above should be:

ColumA

MV

ZX

05

12

Respected Advisor
Posts: 3,156

Re: Leading 0

This works for your presented data. If you have more complex scenario, please exhaust them in your post.

data have;

input ColumA$2.;

if length(ColumA)=1 and anydigit(ColumA)>0 then ColumA=cats('0',ColumA);

cards;

MV

ZX

5

12

;

Haikuo

Ask a Question
Discussion stats
  • 1 reply
  • 150 views
  • 0 likes
  • 2 in conversation