Help using Base SAS procedures

How to display leading zero in a numeric variable?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

How to display leading zero in a numeric variable?

Hi SAS Forum,

Could anyone please let me know how to display leading zeros in a numeric field in the output SAS data set.

data have ;

input acctnum month ;

cards;

111 05

222 05

222 05

222 06

222 07

333 09

333 09

;

run;

I wanted to display all the values for “month” variable as 05, 06, 07 etc in the output SAS dataset instead of displaying as 5,6,7 etc.

But when I run above program, all values for variable month are displayed as 5,6,7 etc.

Documentation provides below approach but this approach just write values into the log without producing an output data set.

%macro test;                                                                                   

                                                                                                            

  %do i=1 %to 100; 

    %let val=%sysfunc(putn(&i,z3.));

    %put &val;                                                                                                                   

                                                                       

  %end;                                                                                                                                

                                                                                                                                       

%mend;                                                                                                                                 

                                                                                                                                       

%test

Thanks

Mirisa


Accepted Solutions
Solution
‎06-26-2014 09:32 AM
Super Contributor
Posts: 275

Re: How to display leading zero in a numeric variable?

format month z2.;

View solution in original post


All Replies
Solution
‎06-26-2014 09:32 AM
Super Contributor
Posts: 275

Re: How to display leading zero in a numeric variable?

format month z2.;

Occasional Contributor
Posts: 5

Re: How to display leading zero in a numeric variable?

data want;

     set have;

     format month z2.;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 401 views
  • 4 likes
  • 3 in conversation