by sql: data have; input identifier $ year value; cards; A 1998 4 A 1999 3 A 2000 2 A 2001 1 A 2002 4 A 2003 6 A 2004 8 A 2005 0 A 2006 6 A 2007 4 A 2008 3 A 2009 1 A 2010 2 B 1998 3 B 1999 6 B 2000 9 B 2001 0 B 2002 7 B 2003 4 ; proc sql; create table temp as select a.identifier, a.year,b.value from have as a , have as b where a.identifier=b.identifier and (b.year between a.year-3 and a.year); create table want as select identifier,year,mean(value) as M_value from temp group by identifier,year; quit;
... View more