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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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