hi guys, i have a question on this problem. So if i sort the dataset given above by indt_id year firm_id to get what i have shown here and run the following code i am not getting the right avg Whats wrong with my code ? data sorted; set have; by indt_id year firm_id; count=0; if not first.year then do; count=count+1; sum+return;end; if last.year then do; avg=sum/count;output; end; proc print;run; Obs firm_id SIC Year Return Indt_id 1 1001 3100 1990 0.01 310 2 1002 3101 1990 0.70 310 3 1003 3101 1990 0.20 310 4 1001 3100 1991 0.20 310 5 1002 3101 1991 -0.50 310 6 1003 3101 1991 0.40 310 7 1001 3100 1992 0.30 310 8 1002 3101 1992 0.20 310 9 1003 3101 1992 0.70 310 10 1001 3100 1993 0.70 310 11 1002 3101 1993 0.40 310 12 1003 3101 1993 -0.50 310 13 1001 3100 1994 -0.50 310 14 1002 3101 1994 0.40 310 15 1003 3101 1994 0.20 310 16 1001 3100 1995 0.20 310 17 1002 3101 1995 0.20 310 18 1003 3101 1995 0.20 310 19 1001 3100 1996 0.40 310 20 1002 3101 1996 0.20 310 21 1003 3101 1996 0.20 310 22 1004 3303 1990 0.40 330 23 1006 3300 1990 -0.50 330 24 1004 3303 1991 0.20 330 25 1006 3300 1991 0.90 330 26 1004 3303 1992 0.20 330 27 1006 3300 1992 0.20 330 28 1004 3303 1993 -0.50 330 29 1006 3300 1993 0.09 330 30 1004 3303 1994 0.90 330 31 1006 3300 1994 0.09 330 32 1004 3303 1995 0.22 330 33 1006 3300 1995 0.22 330 34 1004 3303 1996 0.10 330 35 1006 3300 1996 0.10 330
... View more