How to use the MOD Function in SAS?

The MOD function in SAS is a mathematical function that returns the remainder of a division operation. It takes two arguments and returns the remainder of the first argument divided by the second argument. It is useful for evaluating data that is divided into specific categories, such as in a survey or poll. It can also be used to check for odd or even numbers, or to determine if a number is divisible by another number. The MOD function is an easy and versatile tool to use in SAS programming.


You can use the MOD function in SAS to calculate the remainder from a division operator

This function uses the following syntax:

MOD(dividend, divisor)

where:

  • dividend: The number to divide
  • divisor: The number to divide by

The following example shows how to use this function in practice.

Example: How to Use the MOD Function in SAS

Suppose we have the following dataset in SAS:

/*create dataset*/
data my_data;
    input dividend divisor;
    datalines;
36 6
10 3
15 5
15 6
10 7
22 4
24 4
30 8
;
run;

/*view dataset*/
proc print data=my_data;

The following code shows how to use the MOD function to create a new column that shows the remainder from dividing the values in the dividend column by the values in the divisor column of each row:

/*calculate remainder for each row*/
data new_data;
    set my_data;
    mod = mod(dividend, divisor);
run;

/*view new dataset*/
proc print data=new_data;

The new column called mod shows the remainder from dividing the values in the dividend column by the values in the divisor column of each row.

For example:

  • 6 goes into 36 exactly six times with a remainder of 0.
  • 3 goes into 10 three times with a remainder of 1.
  • 5 goes into 15 exactly three times with a remainder of 0.
  • 6 goes into 15 two times with a remainder of 3.

And so on.

Note: You can find the complete documentation for the SAS MOD function .

The following tutorials explain how to perform other common tasks in SAS:

x