BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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

1 REPLY 1
Haikuo
Onyx | Level 15

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 1105 views
  • 0 likes
  • 2 in conversation