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; 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 580 views
  • 3 likes
  • 2 in conversation