rzaa
Programmer
- May 19, 2008
- 2
Hi,
I have the following data:
Tick Date1 Date2 Cat. value
A x 12 a1 0.23
A x 15 a3 0.75
A x 19 a1 0.65
A x 22 a6 0.16
A x 25 a3 0.87
A x 30 a4 0.65
Data is sorted by Tick Date1 Date2.
I need to calculate an accumulating average of the variable value. Such that the second observation would be (0.23+0.75)/2. The tricky part is that each Cat. value can only count once in the average. Thus the average in the third period should only include the most recent Cat. value (0.75+0.65)/2 not (0.23+0.75+0.65)/3.
The average for the last obs should only include 4 observations the two most recent in cat. a1 and a3 and the then a6 and a4. (0.65+0.16+0.87+0.65)/4.
I made the simple average where all observations within each group of Tick and Date1 is included:
if first.Date1 then do;
var1 = 1;
Var2=value;
end;
else do;
Var1=Var1+1;
Var2=Var2+value;
end;
The average is then simply Var3=Var2/Var1.
I have struggling to find a way to exclude the oldest values(in terms of date2) from the average.
Any help would really be appreciated.
Thanks!
Rasmus
I have the following data:
Tick Date1 Date2 Cat. value
A x 12 a1 0.23
A x 15 a3 0.75
A x 19 a1 0.65
A x 22 a6 0.16
A x 25 a3 0.87
A x 30 a4 0.65
Data is sorted by Tick Date1 Date2.
I need to calculate an accumulating average of the variable value. Such that the second observation would be (0.23+0.75)/2. The tricky part is that each Cat. value can only count once in the average. Thus the average in the third period should only include the most recent Cat. value (0.75+0.65)/2 not (0.23+0.75+0.65)/3.
The average for the last obs should only include 4 observations the two most recent in cat. a1 and a3 and the then a6 and a4. (0.65+0.16+0.87+0.65)/4.
I made the simple average where all observations within each group of Tick and Date1 is included:
if first.Date1 then do;
var1 = 1;
Var2=value;
end;
else do;
Var1=Var1+1;
Var2=Var2+value;
end;
The average is then simply Var3=Var2/Var1.
I have struggling to find a way to exclude the oldest values(in terms of date2) from the average.
Any help would really be appreciated.
Thanks!
Rasmus