data bmt5r; set bmt5; format Filing_Date yymmddn8.; run; data bmt5rr; /*Making connecting identifiers*/ set bmt5r; d_10 = intnx('day',Filing_Date,-10); d_9 = intnx('day',Filing_Date,-9); d_8 = intnx('day',Filing_Date,-8); d_7 = intnx('day',Filing_Date,-7); d_6 = intnx('day',Filing_Date,-6); d_5 = intnx('day',Filing_Date,-5); d_4 = intnx('day',Filing_Date,-4); d_3 = intnx('day',Filing_Date,-3); d_2 = intnx('day',Filing_Date,-2); d_1 = intnx('day',Filing_Date,-1); d_0 = intnx('day',Filing_Date,0); d1 = intnx('day',Filing_Date,1); d2 = intnx('day',Filing_Date,2); d3 = intnx('day',Filing_Date,3); d4 = intnx('day',Filing_Date,4); d5 = intnx('day',Filing_Date,5); d6 = intnx('day',Filing_Date,6); run; proc sql; /*Merging by connecting identifiersto obtain PRICE from CRSP*/ create table d_10 as select a.* , b.* from CRSP1 a inner join bmt5rr b on a.crspcusip6 = b.cusip6 and a.DATE - b.d_10 >=0 having (a.DATE - b.d_10)=min(a.DATE - b.d_10); quit; proc sql; /*Merging by connecting identifiers to obtain PRICE from CRSP*/ create table d_9 as select a.* , b.* from CRSP1 a inner join bmt5rr b on a.crspcusip6 = b.cusip6 and a.DATE - b.d_9 >=0 having (a.DATE - b.d_9)=min(a.DATE - b.d_9); quit; Hi All, I need -10 to +60 interval from specific dates(Filling_Date), and try to obtain daily stock price returns' standard deviations using different intervals. However, my SAS code is so inefficient. 1) Is there other codes to have '-10 to +60 day's interval at once other than specifying -10, -9 to +60 each? What I did is to need to create more than 70 separate data files and these are... hassles. 2)If I have price information from -10days of Filing_Date to +60 days, How can I get variances or standard deviations? I know SAS code calculating these but it only works on a single variable but not across variables. So long as I follow the lengthy code above, I will have D-10 to D60 and these match with Price_10 to Price60, and finally, Return_9 to Return_60 from the simple calculation price_10/Price_9 and so on. SO, I can get returns anyway. BUT I do not have any clue to calculate Var or STD across returns. These are quite tough... I may need other codes. Please share your better ideas!! Thank you!! Ah...there should be some missing values as d_# cannot be matched with DATE(CRSP trading dates). I did not put the code that solves this issue and this issue is not my worry at all.
... View more