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

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

 

ChrisNZ
Tourmaline | Level 20

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

 

 

Tom
Super User Tom
Super User

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

 

 

whs278
Quartz | Level 8

 

 

 

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.

 

FreelanceReinh
Jade | Level 19

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.

 

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
  • 5 replies
  • 1872 views
  • 1 like
  • 5 in conversation