MOD Function

Returns the remainder from the division of the first argument by the second argument, fuzzed to avoid most unexpected floating-point results.

Category: Mathematical
Returned data type: DOUBLE

Syntax

Arguments

expression-1

specifies any valid SQL expression that evaluates to a numeric value. This argument specifies the dividend.

Data type DOUBLE
See <sql-expression>
FedSQL Expressions

expression-2

specifies any valid SQL expression that evaluates to a numeric value. This argument specifies the divisor.

Restriction expression-2 cannot be 0
Data type DOUBLE
See <sql-expression>
FedSQL Expressions

Details

The MOD function returns the remainder from the division of expression-1 by expression-2. When the result is non-zero, the result has the same sign as the first argument. The sign of the second argument is ignored.
The computation that is performed by the MOD function is exact if both of the following conditions are true:
  • Both arguments are exact integers.
  • All integers that are less than either argument have exact 8-byte floating-point representations.
If either of the above conditions is not true, a small amount of numerical error can occur in the floating-point computation. In this case
  • MOD returns zero if the remainder is very close to zero or very close to the value of the second argument.
  • MOD returns a missing value if the remainder cannot be computed to a precision of approximately three digits or more. In this case, SAS also writes an error message to the log.

Example

The following statements illustrate the MOD function:
Statements
Results
select mod(10,3);
1
select mod(.3,-.1);
0.1
select mod(1.7,.1);
0.1
select mod(.9,.3);
5.55E-17
Last updated: February 23, 2017