Hello,
I have the following code in my program.
a = round(b/c, .001);
However, all the numbers get rounded to the hundredths place instead of the thousandths place. In fact, when I remove the round function, I still only get two decimal places.
Not sure what is going on. Tried using and not using BEST32. informat, but still got the same answer. I got the same result with the DIVISION function as well.
These are the actual numbers.
2538200 / 896 = 80957.81
INFORMAT would have no bearing on display appearance. The Format would.
40 data example; 41 x=2538200 / 896 ; 42 put x= best16.; 43 x = round(x,0.001); 44 put "second " x=; 45 run; x=2832.8125 second x=2832.813
So if you get 80957.81 as a result there is something much more interesting going on then just the display format. Perhaps you should show the entire data step code.
INFORMAT would have no bearing on display appearance. The Format would.
40 data example; 41 x=2538200 / 896 ; 42 put x= best16.; 43 x = round(x,0.001); 44 put "second " x=; 45 run; x=2832.8125 second x=2832.813
So if you get 80957.81 as a result there is something much more interesting going on then just the display format. Perhaps you should show the entire data step code.
It works for me. Show us more of what you are doing.
data T;
x= round(2538200 / 896 ,0.001);
put x= ;
run;
x=2832.813
You have presented a single statement without any context.
Since it looks like an assignment statement let's assume you have run it in a data step.
How did you look at the result? Did you print it? Do something else?
Have you attached a display format to the variable A? How many decimal places did you choose to display in the format you attached to the variable?
871 data _null_; 872 a = 2538200 / 896 ; 873 b = round(a,0.001); 874 put 'BEST32.' / (a b) (=best32.); 875 put '32.2' / (a b) (=32.2); 876 put ' ' / (a b) (= ); 877 878 run; BEST32. a=2832.8125 b=2832.813 32.2 a=2832.81 b=2832.81 a=2832.8125 b=2832.813
It's pretty much the same code I posted.
DATA CENSACS;
SET CENSACS2;
/*AVERAGE FAMILY INCOME*/
INFORMAT B19127_001 B19101_001 FAVINC1A BEST32.;
FAVINC1A = DIVIDE( B19127_001, B19101_001);
RENAME B19127_001 = FAVINC1AN
B19101_001 = FAVINC1AD;
RUN;
Here is the output of PROC CONTENTS. I didn't add any formats.
41 FAVINC1A Num 8 BEST32.
32 FAVINC1AD Num 8 BEST32.
34 FAVINC1AN Num 8 BEST32.
Hello @whs278,
@whs278 wrote:
Here is the output of PROC CONTENTS. I didn't add any formats.
41 FAVINC1A Num 8 BEST32.
(So, BEST32. in your partial PROC CONTENTS output is the informat.)
I guess you can mark @ballardw's reply as the solution because not using any formats, e.g., in PROC PRINT output produces exactly what you've described:
data have;
input b c;
a = round(b/c, .001);
x = b/c;
cards;
72538200 896
;
proc print data=have;
*format a x best12.;
run;
Obs b c a x 1 72538200 896 80957.81 80957.81
Of course the missing digits will appear as soon as you run the code including the FORMAT statement that I've commented out.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.