BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bhandara
Fluorite | Level 6

I have numeric values like:

12

126

145698

I want to convert them into 6 digit character with trailing zeros. The above numbers should appear as:

000012

000126

145698

1 ACCEPTED SOLUTION

Accepted Solutions
nazmul
Quartz | Level 8

data new; set old;

zip5_char15 = put(gvkey, $6.);

length zipx $ 6;

zipx = left(zip5_char15);

gvkey_char = substr(("00000"||zipx),length(zipx),6);

drop  zip5_char15 zipx;

run;

View solution in original post

5 REPLIES 5
nazmul
Quartz | Level 8

data new; set old;

zip5_char15 = put(gvkey, $6.);

length zipx $ 6;

zipx = left(zip5_char15);

gvkey_char = substr(("00000"||zipx),length(zipx),6);

drop  zip5_char15 zipx;

run;

bhandara
Fluorite | Level 6

Thanks. This was very quick. I appreciate it. 

Ksharp
Super User
data have;
input x;
want=put(x,z6.);
cards;
12
126
145698
;
RichardDeVen
Barite | Level 11
The question is about how to get LEADING zeros not TRAILING zeros. Edit your question title if possible.

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
  • 5 replies
  • 1833 views
  • 1 like
  • 4 in conversation