BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
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; 
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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; 

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

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; 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 897 views
  • 3 likes
  • 2 in conversation