03-30-2017 02:44 PM
I wantto round 6274.5679 to the nearest integer to get 6275
Here is what I wrote data want ; set have ; format newvar 6. ; newvar = Round(oldvar,1); run; the error i get is Variable is oldvar uninitialized.
What mistake am I making.
03-30-2017 02:56 PM
If you want the integer portion of a variable, the INT function is what you are looking for
data have; value = 6274.5679; round_value = round(value); int_value = int(value); put round_value; put int_value; run;
03-30-2017 03:01 PM
data _null_; x=6274.4999; put x hex16.; /* here is the problem non-terminating mantissa cannot represent the number exactly - you have lost already. 6274.4999 40B8827FF9724745 like 1/3 in decimal (never is exact) 0.3333333333333 */ x=62744999; put x hex16.; /* got it exactly 62744999 418DEB4D38000000 */ x=6274.5; put x hex16.; /* got it exactly (when mantissa is a power of 2**(-n)) 6274.5 40B8828000000000 */ /* possible solution; summing in the integer domain is exact (given no overflow); I don not think it has to be this complex; */ input numchr $9.; put numchr; numchr=compress(numchr,'.'); exact_integer=input(numchr,9.); put exact_integer hex16.; * in microcode this should be a bit shifting operation and should be exact?; res=round(exact_integer,10000); res=res/10000; put res 9.4; cards4; 6274.4999 6274.5000 6274.5001 ;;;; run;quit;