BookmarkSubscribeRSS Feed
AnnaBrown
Amethyst | Level 16

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.

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

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