From: db on 11 Jun 2010 18:33 Hi, I am trying to calculate correlation coefficeint for fixed period by date and time I would like to calculate correlation coefficient starting at 7:01:00 (since my dataset starts at 7:00:00) and ending at 21:00:00 everyday. I got second logic from this forum but this logic is to calculate rolling window of correlation coefficient. Could anyone help how to solve this problem ? Thank you so much ! data input; format date:mmddyy10. time :time7.; *informat date date10. time time7.; input date $ time $ stock1 stock2; cards; 01/04/2010 7:00:00 5989.5 1115.25 01/04/2010 7:01:00 5998.5 1116 01/04/2010 7:02:00 5996.5 1115.75 01/04/2010 7:05:00 6000 1115.5 01/04/2010 20:55:00 6042 1128.5 01/04/2010 20:56:00 6040.5 1128.5 01/04/2010 20:57:00 6040.5 1128.75 01/04/2010 20:58:00 6040.5 1128.5 01/04/2010 20:59:00 6040.5 1128.5 01/04/2010 21:00:00 6036 1128.75 01/05/2010 7:00:00 6035.5 1128.5 01/05/2010 7:01:00 6037 1128.5 01/05/2010 7:02:00 6037 1128.5 01/05/2010 7:03:00 6038 1128.5 01/05/2010 7:06:00 6038.5 1128.25 01/05/2010 20:56:00 6042 1131.5 01/05/2010 20:57:00 6042.5 1132 01/05/2010 20:58:00 6042 1132 01/05/2010 20:59:00 6041.5 1131.75 01/05/2010 21:00:00 6041.5 1132.25 01/06/2010 7:00:00 6039 1129.75 01/06/2010 7:01:00 6035 1129.25 01/06/2010 7:02:00 6035 1129.5 01/06/2010 7:07:00 6035 1129.25 01/06/2010 20:38:00 6036 1134 01/06/2010 20:39:00 6038.5 1134.25 01/06/2010 20:59:00 6035.5 1133 01/06/2010 21:00:00 6035.5 1133 ; run; %let wsize=2; data corr; array xx(&wsize) (&wsize * 0); array yy(&wsize) (&wsize * 0); retain xx : yy :; x2remove = xx(mod(_n_ - 1, &wsize) + 1); *put x2remove; y2remove = yy(mod(_n_ - 1, &wsize) + 1); set input ( rename = (stock2 = y stock1 = x)) ; xx(mod(_n_ - 1, &wsize) + 1) = x; yy(mod(_n_ - 1, &wsize) + 1) = y; sumx + x - x2remove ; sumxsq + x**2 - x2remove**2; sumy + y - y2remove; sumysq + y**2 - y2remove**2; sumxy + x * y - x2remove * y2remove; if _n_ >= &wsize then r = (sumxy - sumx * sumy / &wsize)/sqrt((sumxsq - sumx ** 2 / &wsize) * (sumysq - sumy ** 2 / &wsize)); run;
|
Pages: 1 Prev: How do I disable sort when creating a new dataset from another? Next: Data Structure |