Again, I am not seeing a question here. You have mentioned all the procedures you need to do what you want - sort, rank, means etc. What have you tried, what is not working. And example of getting previous 11 months, and next 11 months could be like this:
data have;
call streaminit(85765);
do month=1 to 10;
do Company=1, 2, 5, 7, 9, 10, 13, 15, 16, 18, 20, 21, 22;
value = round(rand("UNIFORM") * 25, 0.5);
output;
end;
end;
run;
proc sql;
create table INTER as
select A.COMPANY,
A.MONTH,
(select sum(VALUE) from HAVE where COMPANY=A.COMPANY and MONTH between A.MONTH-11 and A.MONTH) as PREV_11,
(select sum(VALUE) from HAVE where COMPANY=A.COMPANY and MONTH between A.MONTH and A.MONTH+11) as NEXT_11
from WORK.HAVE A
order by COMPANY,MONTH;
quit;
... View more