BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
slchen
Lapis Lazuli | Level 10

format month z2.;

sarathannapareddy
Fluorite | Level 6

data want;

     set have;

     format month z2.;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 3782 views
  • 4 likes
  • 3 in conversation