BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

data ex;

a=23.964 ;

run;

create new variable and should be in numeric format only

how to directly we can divide the number number with one decimal

 

ex:  23.9

10 REPLIES 10
thanikondharish
Calcite | Level 5
Sorry I need exact number If I use your format it is showing 23
mklangley
Lapis Lazuli | Level 10

@Kurt_Bremser I believe applying format 8.1 would actually cause to show up as 24.0 (not 23.9, as in @PGStats's example c), since rounding is also applied. But it would definitely have a digit after the decimal point, like you indicated.

data ex;
    a=23.964 ;
    format a 8.1;
run;
proc print; run;

mklangley_0-1595355620753.png

Kurt_Bremser
Super User

@thanikondharish wrote:
Sorry I need exact number If I use your format it is showing 23

On top of what was already said, this (rounding up) is mathematically correct behavior for values where the first "discarded" digit is 5 or greater, and should usually be applied.

"Exact number" is of course a very funny term when you are actively reducing precision in the first place. By applying a format with a limited number of digits, you have already thrown the concept of "exact" over board.

ballardw
Super User

 

b = floor (a*10)/10;

 

if the object is to always round down to multiples of 0.1

otherwise you may need to provide more rules.

 

mklangley
Lapis Lazuli | Level 10

Truncation without rounding:

data ex;
   a = 23.964;
   b = int(a*10)/10;
run;

See helpful article here.

PGStats
Opal | Level 21
data ex;
a = 23.964 ;
b = round(a, 0.1);
c = int(a*10)/10;
format b c 8.1;
run;

proc print; run;
Obs. 	a 	b 	c
1 	23.964 	24.0 	23.9
PG
PaigeMiller
Diamond | Level 26

Just remember that by converting to 23.9 using the above methods (except formatting), this number cannot be represented exactly in binary, and so that may cause issues.

--
Paige Miller
Ksharp
Super User
proc format ;
picture fmt
 low-high='0009.9';
run;

data ex;
a = 23.964 ;
format a fmt.;
run;

proc print;run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 5121 views
  • 1 like
  • 7 in conversation