What is the MOD function in SAS and how can it be used? Can you provide an example? 2

What is the MOD function in SAS and how can it be used? Can you provide an example?

The MOD function in SAS stands for “modulo” and is used to calculate the remainder after dividing two numbers. It can be used to determine if a number is even or odd, or to group data into specific intervals. The syntax for the MOD function is “MOD(x,y)” where x and y are the two numbers being divided. The result will be the remainder after dividing x by y.

For example, if we have a dataset with student scores on a test and we want to group them into letter grades, we can use the MOD function. Let’s say the passing score is 70 and we want to group scores between 0-69 as “F”, 70-79 as “C”, 80-89 as “B”, and 90-100 as “A”. We can use the following code:

data grades;
set scores;
if MOD(score, 10) = 0 then grade = “F”;
else if score >= 70 and MOD(score,10) = 0 then grade = “C”;
else if score >= 80 and MOD(score,10) = 0 then grade = “B”;
else if score >= 90 and MOD(score,10) = 0 then grade = “A”;
run;

This code will create a new variable called “grade” and assign each score to the appropriate letter grade based on the MOD function. This allows us to easily group the data and analyze it further.

Use the MOD Function in SAS (With Example)


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 printdata=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 printdata=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:

Cite this article

stats writer (2024). What is the MOD function in SAS and how can it be used? Can you provide an example?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/what-is-the-mod-function-in-sas-and-how-can-it-be-used-can-you-provide-an-example/

stats writer. "What is the MOD function in SAS and how can it be used? Can you provide an example?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/what-is-the-mod-function-in-sas-and-how-can-it-be-used-can-you-provide-an-example/.

stats writer. "What is the MOD function in SAS and how can it be used? Can you provide an example?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/what-is-the-mod-function-in-sas-and-how-can-it-be-used-can-you-provide-an-example/.

stats writer (2024) 'What is the MOD function in SAS and how can it be used? Can you provide an example?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/what-is-the-mod-function-in-sas-and-how-can-it-be-used-can-you-provide-an-example/.

[1] stats writer, "What is the MOD function in SAS and how can it be used? Can you provide an example?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. What is the MOD function in SAS and how can it be used? Can you provide an example?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top