Sample 24674: Determining odd versus even using the MOD function
Output only even number observations.
Note:
The MOD function returns the remainder when values are
divided.
In this sample, when dividing i by 2, there will be
no remainder for the even observations (2,4,6,8 and 10).
If there is a remainder, the current observation has to
be an odd numbered observation. This program outputs
only the even numbered observations to a new data set.
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.
/* 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 */
/* argument-1 by argument-2. If the remainder is zero, when */
/* the second argument is 2, then the first argument must be */
/* even...therefore, output the observation. */
if mod(i,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
Output only even number observations.
| 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 |