Contributor
Posts: 56

# Sum of row observations with different intervals

I recently encountered the problem in a stock even study. The pseudo data looks like
DATE Index Volume StockReturn ReturnInterval
19990101 0.1 200 0.02 .
19990102 0.32 300 0.03 1
19990103 0.2 0 0 .
19990104 0.1 200 0.04 2
19990105 0.22 0 0 .
19990108 0.03 0 0 .
19990109 0.2 100 0.01 3
Here the volume 0 means on that day, the stock is not traded, but we still have the index return for the overall market. The return interval gives the number of returns between two traded dates. What I want to do is to sum of the index return over each return interval. ie: on day 19990102, the new index is itself 0.32, on day 19990104, the new index return should be 0.2+0.1, and on day 19990109, the new index return should be 0.22+0.03+0.2.

I hope any ppl can help me with this.. Heaps Thanks here first.
Not applicable
Posts: 0

## Re: Sum of row observations with different intervals

this looks too much in need of the original data order to be suitable for SQL. However, the DATA STEP can easily use the ordered information:[pre]data idx_ret_sums( keep= DATE idx_ret_sum ) ;
set pseudo_data ;
idx_ret_sum + Index ;
if not missing( returnInterval ) ;
output ;
idx_ret_sum = 0 ; * prepare accumulator for next interval;
run ;
proc print ;
run;[/pre]

PeterC
Contributor
Posts: 56