If you are subtracting beginning price from end price here you go: data have; infile cards dsd; input Cusip$ Months$ price; cards; 111111,1985 Aug,2.05 111111,,, 111111,1990 Jul,5.36 100000,1985 Aug,5.8 100000,, 100000,1990 Jul,8.6 ; data prep; set have; if not missing(months) then do; _month = month(input(put(cats('01',scan(months,2,' '),2015),$9.),date9.)); end; _year = scan(months,1,' '); run; proc sort data=prep out=prep2;by cusip _year _month;where not missing(months); data want; set prep2; retain _begin; by cusip _year _month; if first.cusip then _begin = price; if last.cusip then _end = price; return = _end-_begin; drop _:; run;
... View more