ROUNDZ Function


ROUNDZ Function

Rounds the first argument to the nearest multiple of the second argument, with zero fuzzing

Category: Truncation

Syntax

ROUNDZ ( argument <, rounding-unit >)

Arguments

argument

  • is a numeric constant, variable, or expression to be rounded.

rounding-unit

  • is a positive, numeric constant, variable, or expression that specifies the rounding unit.

Details

The ROUNDZ function rounds the first argument to the nearest multiple of the second argument. If you omit the second argument, ROUNDZ uses a default value of 1 for rounding-unit .

Comparisons

The ROUNDZ function is the same as the ROUND function except that:

  • ROUNDZ returns an even multiple when the first argument is exactly halfway between the two nearest multiples of the second argument. ROUND returns the multiple with the larger absolute value when the first argument is approximately halfway between the two nearest multiples .

  • When the round-off unit is less than one and not the reciprocal of an integer, the result that is returned by ROUNDZ might not agree exactly with the result from decimal arithmetic. ROUNDZ does not fuzz the result. ROUND performs extra computations , called fuzzing, to try to make the result agree with decimal arithmetic.

Examples

Example 1: Comparing Results from the ROUNDZ and ROUND Functions

The following example compares the results that are returned by the ROUNDZ and the ROUND function.

 options pageno=1 nodate linesize=60 pagesize=60;  data test;     do i=10 to 17;        Value=2.5 - 10**(-i);        Roundz=roundz(value);        Round=round(value);        output;     end;     do i=16 to 12 by -1;        value=2.5 + 10**(-i);        roundz=roundz(value);        round=round(value);        output;     end;  run;  proc print data=test noobs;     format value 19.16;  run; 

The following output shows the results.

Output 4.46: Results That Are Returned by the ROUNDZ and ROUND Functions
start example
 The SAS System                             1   i                   Value     Roundz    Round  10      2.4999999999000000        2        2  11      2.4999999999900000        2        2  12      2.4999999999990000        2        3  13      2.4999999999999000        2        3  14      2.4999999999999900        2        3  15      2.4999999999999900        2        3  16      2.5000000000000000        2        3  17      2.5000000000000000        2        3  16      2.5000000000000000        2        3  15      2.5000000000000000        3        3  14      2.5000000000000100        3        3  13      2.5000000000001000        3        3  12      2.5000000000010000        3        3 
end example
 

Example 2: Sample Output from the ROUNDZ Function

These examples show the results that are returned by ROUNDZ.

SAS Statement

Results

var1=223.456;

x=roundz(var1,1);

put x 9.5;

223.00000

var2=223.456;

x=roundz(var2,.01);

put x 9.5;

223.46000

x=roundz(223.456,100);

put x 9.5;

200.00000

x=roundz(223.456);

put x 9.5;

223.00000

x=roundz(223.456,.3);

put x 9.5;

223.50000

See Also

Functions:

  • 'ROUND Function' on page 789

  • ' ROUNDE Function' on page 796




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net