Here is an example where you find a useful application of the MOD function. Most people would skip right over this function when reading their SAS manuals, hardly remembering that they once knew what a modulus was (eleventh grade math?).To review, a number n modulo m, is the remainder when n is divided by m.For instance,5 mod 3 is 2 (when you divide 5 by 3, you get 1 with a remainder of 2).And 17 mod 3 is also 2 (3 goes into 17 five times with a remainder of 2). How is this useful? Suppose you want to select every third observation from a SAS data set.The very simple code following, using the MOD function, does just that:
The function MOD(n,m) (read n mod m) is used here with the automatic SAS System variable _N_.This variable is automatically created when a SAS data set is built and is incremented by 1 for each iteration of the DATA step. _N_ is loosely referred to as the observation counter and is used here as the first argument with 3 (the selection criteria) as the second. MOD (_N_, 3) is equal to 1 when _N_ is 1, 4, 7, etc. (i.e. every third record beginning with the first observation).
Caution:Don't automatically accept _N_ as a true observation counter in all DATA steps (that's why we said loosely). _N_ is incremented by 1 at each iteration of the DATA step. DATA steps that contain loops and OUTPUT statements may cause the relationship of the observation number and the internal variable _N_ to fall apart. This is not a problem with the system—it's the way it was designed to work. You may very well want to include code such as N+1; in a program to create your own observation counter.
Suppose you want to convert pounds to kilograms and inches to centimeters, and you want the results rounded to the nearest kilogram and the nearest tenth of a centimeter (millimeter) respectively. You can use the ROUND function to accomplish this task.
SAS Programming Related Tutorials
|SASS (Syntactically Awesome Style sheets) Tutorial||R Programming language Tutorial|
SAS Programming Related Interview Questions
|Logistics Interview Questions||SAS Programming,SQL server Interview Questions|
|Clinical SAS Interview Questions||SASS (Syntactically Awesome Style sheets) Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||R Programming language Interview Questions|
|SAS DI Interview Questions||Advanced SAS Interview Questions|
|Base Sas Interview Questions||SAS Macro Interview Questions|
|Clinical Data Management Interview Questions|
Sas Programming Tutorial
Input And Infile
Set, Merge, And Update
Table Lookup Tools
Proc Means And Proc Uimivariate
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.