I don't quite understand your desired logic...but you can join the table to itself with appropriate date criteria to get all of the values on one row...then do the math. proc sql; create table want as select t1.prod, t1.cust, t1.req_ord_qty, t2.req_ord_qty as req_ord_qty_2, t3.req_ord_qty as req_ord_qtr_3 . . . from have t1 left join have t2 on t1.prod=t2.prod and t1.cust=t2.cust and intnx('month',t1.per_dt,-1,'begin')=t2.per_dt left join have t3 on t1.prod=t3.prod and t1.cust=t3.cust and intnx('month',t1.per_dt,-2,'begin')=t3.per_dt left join have t4 on t1.prod=t4.prod and t1.cust=t4.cust and intnx('month',t1.per_dt,-3,'begin')=t4.per_dt left join have t5 on t1.prod=t5.prod and t1.cust=t5.cust and intnx('month',t1.per_dt,-4,'begin')=t5.per_dt left join have t6 on t1.prod=t6.prod and t1.cust=t6.cust and intnx('month',t1.per_dt,-5,'begin')=t6.per_dt left join have t7 on t1.prod=t7.prod and t1.cust=t7.cust and intnx('month',t1.per_dt,-6,'begin')=t7.per_dt ; quit;
... View more