BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm in the final stages of a data standardisation effort here at work.
There are two data columns, each being of type CHAR. They mostly contain numeric IDs, but some contain letters in the middle of the number strings as well. What I wish to do is ensure that all of the variables contain 10 characters, and if they contain less than that, pad out the left-hand-side with 0s.
If the variables were guaranteed to be wholly numeric I would simply convert to a number and then use PUT with the Zw. format, but that isn't applicable here.

Any suggestions?
1 REPLY 1
deleted_user
Not applicable
Nevermind - I discovered the REPEAT function.

Here's a solution in macro format, to stop this topic being a waste of space...
%macro fillfromleftwithzero(table,variable,varlen);
data &table.;
set &table.;
&variable. = REPEAT("0",&varlen.-length(&variable.)) || &variable.;
run;
%mend; /*fillfromleftwithzero*/

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 768 views
  • 0 likes
  • 1 in conversation