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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1116 views
  • 0 likes
  • 2 in conversation