I need to create a variable that fills one cell 10 observations backward and one forward in SAS. A condition must be met. It is hard to explain, so the data below might help.
So far I tried to use proc expand to generate 10 leads and get them into one variable but that looks ridiculous and does not really work.
proc expand data=optionsreturns out=optionsreturns2;by secid cp_flag;
convert best_bid = ann_best_bid1 /transformout = (lead 1);
convert best_bid = ann_best_bid2 /transformout = (lead 2);
convert best_bid = ann_best_bid3 /transformout = (lead 3);
convert best_bid = ann_best_bid4 /transformout = (lead 4);
convert best_bid = ann_best_bid5 /transformout = (lead 5);
convert best_bid = ann_best_bid6 /transformout = (lead 6);
convert best_bid = ann_best_bid7 /transformout = (lead 7);
convert best_bid = ann_best_bid8 /transformout = (lead 8);
convert best_bid = ann_best_bid9 /transformout = (lead 9);
convert best_bid = ann_best_bid10 /transformout = (lead 10);
convert best_offer = ann_best_offer1 /transformout = (lead 1);
convert best_offer = ann_best_offer2 /transformout = (lead 2);
convert best_offer = ann_best_offer3 /transformout = (lead 3);
convert best_offer = ann_best_offer4 /transformout = (lead 4);
convert best_offer = ann_best_offer5 /transformout = (lead 5);
convert best_offer = ann_best_offer6 /transformout = (lead 6);
convert best_offer = ann_best_offer7 /transformout = (lead 7);
convert best_offer = ann_best_offer8 /transformout = (lead 8);
convert best_offer = ann_best_offer9 /transformout = (lead 9);
convert best_offer = ann_best_offer10 /transformout = (lead 10);
run;
the Option Contract Price P=Put of the Option ID Bid Across All Ask Across All Vol Average if Negative) Price WANT COUNT
10006273 19980303 C 19980418 5168 9.875 10.125 0 34.6875 .
10006273 19980304 C 19980418 5168 9 9.25 0 33.8125 .
10006273 19980305 C 19980418 5168 9 9.25 0 33.75 . 0.25 -10
10006273 19980313 C 19980418 5168 12.375 12.75 0 37.3125 . 0.25 -9
10006273 19980331 C 19980418 5168 19.625 20.125 0 44.625 . 0.25 -8
10012764 19960105 C 19960120 5168 0.375 0.4375 71 30.5 . 0.25 -7
10012764 19960108 C 19960120 5168 0.1875 0.375 0 30.1875 . 0.25 -6
10012764 19960109 C 19960120 5168 0.0625 0.1875 0 29.375 . 0.25 -5
10012764 19960110 C 19960120 5168 0.125 0.25 0 28.75 . 0.25 -4
10012764 19960111 C 19960120 5168 0 0.125 15 28.875 . 0.25 -3
10012764 19960112 C 19960120 5168 0 0.125 0 28.375 . 0.25 -2
10012764 19960115 C 19960120 5168 0 0.125 0 28.5 . 0.25 -1
10012764 19980824 C 19960120 5168 0.25 0.4375 28 29.25 24/08/1998 0.25 0
10022220 19960205 C 19960420 5168 18.75 19.125 26 33.625 .