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.

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