0
votes
Dv1  Dv2  Dv3  Dv4  Dv5  Dv6  Dv7  Dv8
 1    1    2    5    5    7    9    9
 3    4    8    8    8    9   10    .
 2    5    9   11   13   13    .    .
 4    4    5    9    9    .    .    .
 2    6    7    9    .    .    .    .
 2    4    6    .    .    .    .    .
 1    3    .    .    .    .    .    .
 3    .    .    .    .    .    .    .

I have a much larger version of the above data. Each column has a factor which when multiplied by the previous column data gives the current column data.

The factor = (sum of the previous 5 rows)/(sum of the previous 5 rows one column to the left) eg. Column 2 factor = (3+4+6+4+5)/(1+2+2+4+2) = 2 and the resulting data being:

Dv1  Dv2  Dv3  Dv4  Dv5  Dv6  Dv7  Dv8
 1    1    2    5    5    7    9    9
 3    4    8    8    8    9   10    .
 2    5    9   11   13   13    .    .
 4    4    5    9    9    .    .    .
 2    6    7    9    .    .    .    .
 2    4    6    .    .    .    .    .
 1    3    .    .    .    .    .    .
 3    6    .    .    .    .    .    .

Use any available rows if 5 do not exist above the data.

I want to fill this out data using SAS. My problem is how to sum the previous 5 rows, I'm fairly confident I can proceed from there.

Many thanks in advance!

1

1 Answers

1
votes

LAG function.

sum_prev5 = lag(x) + lag2(x) + lag3(x) + lag4(x) + lag5(x);