Sample 24674: Determining odd versus even using the MOD function
The Full Code tab has an example that uses the MOD function to output only even-numbered observations from the input data set.
The MOD function returns the remainder from the division of the first argument by the second argument. In this sample, the first argument to the function is the observation number and the second argument is 2. Setting the second argument to 2 will result in a remainder of 0 when the observation number is an even number.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This example uses the MOD function to output only the even-numbered observations from the input data set.
/* Create sample data set */
data one;
do i=1 to 10;
output;
end;
run;
data two;
set one;
/* The MOD function returns the remainder from the division of the */
/* first argument by the second argument. This sample uses the MOD function to divide the observation number by 2. */
/* A remainder of 0 indicates the observation number is even and the observation is output. */
if mod(_n_,2)=0 then output;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs i
1 2
2 4
3 6
4 8
5 10
The results of the MOD function can be used to determine whether a value is odd or even.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Mathematical
|
Date Modified: | 2006-05-27 03:02:59 |
Date Created: | 2004-09-30 14:09:03 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |