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
Just use a numeric format with one decimal, e. g.
format a 8.1;
@thanikondharish wrote:
Sorry I need exact number If I use your format it is showing 23
Bullshit. See @PGStats post (variable c).
@Kurt_Bremser I believe applying format 8.1 would actually cause a 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;
@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.
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.
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
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.
proc format ;
picture fmt
low-high='0009.9';
run;
data ex;
a = 23.964 ;
format a fmt.;
run;
proc print;run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.