BookmarkSubscribeRSS Feed
AnnaBrown
Community Manager

Hi Community,

 

A common question asked here is how to add leading zeros to a SAS value. SAS' Peter Styliadis, explains the process in this tutorial.

 

 

  

1 REPLY 1
LaurieF
Barite | Level 11

Want to add on something really stupid? This is from the days before %sysfunc, putn and the z format...

 

%let j = %substr(000&j, %length(&j), 4);

For values of j up to 9999, right-justify and zero-fill j. Want longer numbers? Add zeros, and change the last parameter.

 

I used this construct for years, but the documentation was usually fairly thorough.

 

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
  • 1084 views
  • 1 like
  • 2 in conversation