Here is another way: data existing; infile datalines delimiter=','; input id $ monthid new_demand month1 month2 month3; datalines; 1,1,2,3,4,5 1,2,3,.,.,. 1,3,0,.,.,. 1,4,3,.,.,. 1,5,1,.,.,. 2,1,2,3,4,5 2,2,3,.,.,. 2,3,0,.,.,. 2,4,3,.,.,. 2,5,1,.,.,. ; run; data desired; length _month1 _month2 _month3 8; retain _month1 _month2 _month3; if (_n_ = 1) then do; declare hash myhash(); rc = myhash.definekey('id'); rc = myhash.definedata('_month1','_month2','_month3'); myhash.definedone(); end; set existing; by id; if first.id then do; myhash.clear(); _month1= new_demand; _month2=month1 ; _month3=month2; myhash.add(); end; else do; myhash.find(); month1= _month1; month2= _month2; month3= _month3; _month1= new_demand; _month2=month1 ; _month3=month2; myhash.replace(); end; drop _: rc; run; Regards, Naveen Srinivasan
... View more