Previous Page | Next Page

Functions and CALL Routines

ROUNDZ Function



Rounds the first argument to the nearest multiple of the second argument, using zero fuzzing.
Category: Truncation

Syntax
Arguments
Details
Comparisons
Examples
Example 1: Comparing Results from the ROUNDZ and ROUND Functions
Example 2: Sample Output from the ROUNDZ Function
See Also

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:


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.

Results That Are Returned by the ROUNDZ and ROUND Functions

                                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  

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

ROUNDE Function

Previous Page | Next Page | Top of Page