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

Hi all,

 

I have a quick question related to SAS programming. I have a data set and this data set contains of decimals. I want to "0" to the integer and fractional parts of some decimals. I want to explain it by using just quick example. So, I have the following data set:

 

     Observation          Decimal

      1                             32.25

      2                             33.2

      3                              2.56

      4                              1.5

 

And, I want the following data set:

 

     Observation               Decimal           Want

     1                                  32.25              32.25

     2                                  33.4                33.40

     3                                  2.56                02.56

     4                                  1.5                   01.50

 

So, as you can see, I add 0 before the integer part if integer part consists of one character (for example it was 2.56 and i want 02.56 - add 0 before 2, since integer part just one character (2)). Additionally, I add the 0 after the fractional part if fractional part consists of one character (for example it was 33.2 and I want 33.20 - add 0 after 4, since  fractional part just one character).

I hope I can explain it. Many thanks in advance for your help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Ammonite | Level 13

Use the Z format (leading zero format).

data x;
input y;
format y z5.2;
datalines;
 32.25
 33.2
  2.56
 1.5
 ;
 proc print; run;

View solution in original post

1 REPLY 1
WarrenKuhfeld
Ammonite | Level 13

Use the Z format (leading zero format).

data x;
input y;
format y z5.2;
datalines;
 32.25
 33.2
  2.56
 1.5
 ;
 proc print; run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1500 views
  • 1 like
  • 2 in conversation