how to add leading zeros
DATA DS4; INFILE DATALINES; INPUT NUMBER; FORMAT NUMBER Z10.; DATALINES; 1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111111 ; RUN;
You already achieved that:
data ds4;
infile datalines;
input number;
format number Z10.;
datalines;
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
;
run;
proc print data=ds4 noobs;
run;
Result:
number 0000000001 0000000011 0000000111 0000001111 0000011111 0000111111 0001111111 0011111111 0111111111 1111111111
A number does not have leading zeroes by definition, but it can be displayed with leading zeroes, and your format does that.
If you need to store leading zeroes (eg if your number is not a number for calculation, but identification), you have to store the value in a character variable.
@BrahmanandaRao wrote:
how to add leading zeros
DATA DS4; INFILE DATALINES; INPUT NUMBER; FORMAT NUMBER Z10.; DATALINES; 1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111111 ; RUN;
You already achieved that:
data ds4;
infile datalines;
input number;
format number Z10.;
datalines;
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
;
run;
proc print data=ds4 noobs;
run;
Result:
number 0000000001 0000000011 0000000111 0000001111 0000011111 0000111111 0001111111 0011111111 0111111111 1111111111
A number does not have leading zeroes by definition, but it can be displayed with leading zeroes, and your format does that.
If you need to store leading zeroes (eg if your number is not a number for calculation, but identification), you have to store the value in a character variable.
@BrahmanandaRao wrote:
how to add leading zeros
DATA DS4; INFILE DATALINES; INPUT NUMBER; FORMAT NUMBER Z10.; DATALINES; 1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111111 ; RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.