I am trying to create a dummy variable A to indicate the number of ID
appearances. If ID
appears exactly twice, then A
equals 0; if ID
appears more than 2 times, then A
equals 1.
My desired output is as follows:
ID YEAR A
1078 1989 0
1078 1999 0
1161 1969 0
1161 2002 0
1230 1995 0
1230 2002 0
1279 1996 0
1279 2003 0
1447 1993 0
1447 2001 0
1487 1967 1
1487 2008 1
1487 2009 1
1678 1979 0
1678 2002 0
My code is:
data new data;
set data;
by ID YEAR;
if First.ID then count=0;
count+1;
run;
data newdata;
set newdata;
by ID YEAR count;
if sum(count)=3 then A=0;
if sum(count)>3 then A=1;
run;
But the output is incorrect.