Try the code below to see how you can use RDQE (Report Date Quarterly Earnings) and make use of the fact that this data item is a SAS date variable that allows you to add and subtract days. Note that the program creates a d1 and d2 variable that is formatted to be like CRSP dates, but they are actually numbers based on January 1, 1960, being 0.
gvkey= 6066 and year > 2002 and fyr > 0 ;
gvkey smbl date fyr rdqe data1;
d1= rdqe -
d2= rdqe +
10 ; format d1 d2 yymmddn8. ;
d1 d2; run ;
print data =x1; run ;
You do not need to create more date boundaries (for -200 and +40) if you use a CRSP date screening process such as if (date >= d1-200 and date <= d1) or (date >= d2 and date <= d2+40); in the next step (merging with CRSP daily data).