Today is Feb 29, –another leap year! I just found it is a good chance to raise the topic of logic operators again. To determine if 2012 is a leap year, use the straightforward logic expression (demo is SAS, follow the pseudo code in the wiki page of leap year): if mod(year,4) = 0 then […]
Tag: logic operator
Power of Logic Operators: a trick
Suppose you should group people based on their ages as follows:
ID
Age
agegrp
001
1
1
002
4
2
003
5
2
004
5
2
005
2
1
006
4
2
007
5
2
008
2
1
009
9
3
010
8
3
and the rules:
age<4, group 1
4<=age<6, group 2
6<=age<10, group 3
It is a very simple question and you could use the if/else statement without thinking:
data age;
input ID $ age;
datalines;
001 1
002 4
003 5
004 5
005 2
006 4
007 5
008 2
009 9
010 8
;
data age1;
set age;
if age<4 then agegrp=1;
else if […]