Here you go: DATA have; infile cards dsd; informat Item_Id $8. Category $5. Item_Description $24. Date mmddyy10.; format Item_Id $8. Category $5. Item_Description $24. Date mmddyy10.; input Item_Id$ Category$ Item_Description$ Date AGS BC MX; cards; 23555212,Chips,Potato Lays Chips 50 gms,2/1/2015,22,,31 23555212,Chips,Potato Lays Chips 50 gms,3/1/2015,,,33 23555212,Chips,Potato Lays Chips 50 gms,5/1/2015,25,,32 23555212,Chips,Potato Lays Chips 50 gms,6/1/2015,27,, 23555212,Chips,Potato Lays Chips 50 gms,7/1/2015,22,, 35442011,Chips,Chilly Lays Chips 50 gms,2/1/2015,,34, 35442011,Chips,Chilly Lays Chips 50 gms,3/1/2015,,31, 35442011,Chips,Chilly Lays Chips 50 gms,4/1/2015,,, 35442011,Chips,Chilly Lays Chips 50 gms,5/1/2015,,32, 35442011,Chips,Chilly Lays Chips 50 gms,6/1/2015,,34, ; run; proc sql; create table prep as select *,avg(ags) as _avg_ags,avg(bc)as _avg_bc,avg(mx) as _avg_mx from have group by item_id order by item_id,date; data want; set prep; by item_id; if missing(ags) then ags = _avg_ags; if missing(bc) then bc = _avg_bc; if missing(mx) then mx = _avg_mx; drop _:; run;
... View more