Oops I am late to the part,Just for fun and nothing more: data _null_; if _n_=1 then do; if 0 then set have; declare hash myhash(multidata:'YES',ordered:'a'); myhash.definekey('id','p'); myhash.definedata('id','p','nc','mg','mp'); myhash.definedone( ); end; set have end=last; by id p; if ((missing(mp) and missing(mg)) or (missing(mp) or missing(mg))) and myhash.check() ne 0 then rc=myhash.add(); else if myhash.check() ne 0 and not missing(mp) and not missing(mg) then rc=myhash.add(); else if myhash.check()=0 and (missing(mp) and missing(mg)) then rc=myhash.add(); else if myhash.check()=0 and ((not missing(mp) and missing(mg)) or (missing(mp) and not missing(mg))) then do; _mg=mg; _mp=mp; _nc=nc; rc=myhash.find(); if missing(mg) then mg=_mg; if missing(mp) then mp=_mp; myhash.replacedup(); rc=myhash.find_next(); do while(rc=0); if missing(mg) then mg=_mg; if missing(mp) then mp=_mp; myhash.replacedup(); rc=myhash.find_next(); end; mg=_mg; mp=_mp; nc=_nc; myhash.add(); end; else if myhash.check()=0 and not missing(mp) and not missing(mg) then do; _mg=mg; _mp=mp; _nc=nc; rc=myhash.find(); if missing(mg) then mg=_mg; if missing(mp) then mp=_mp; myhash.replacedup(); rc=myhash.find_next(); do while(rc=0); if missing(mg) then mg=_mg; if missing(mp) then mp=_mp; myhash.replacedup(); rc=myhash.find_next(); end; mg=_mg; mp=_mp; nc=_nc; myhash.add(); end; if last then rc=myhash.output(dataset:'want'); run; proc sort data=want; by id p nc; run; Regards, Naveen Srinivasan
... View more