Here's another solution, just so we are clear, that is not in your desired dataset. We've spent more time going back and forth because you don't know how to ask a question and explain what it is you want:
proc sql; create table acc_prep as select *,sum(InjMinor,InjurMajor) as InjNo from acc order by key_id,kroki; proc sort data=veh;by key_id kroki; data veh_count; set veh; by key_id kroki; count+1; Vehcount+1; if first.kroki then do; vehcount = 1; count = 1; end; run; proc sql; create table veh_prep as select *,max(vehcount) as VehNo from veh_count group by kroki order by key_id,kroki; proc sort data=par;by key_id kroki; data par_count; set par; by key_id kroki; count+1; Parcount+1; if first.kroki then do; count = 1; parcount = 1; end; run; proc sql; create table par_prep as select *,max(parcount) as ParNo from par_count group by kroki order by key_id,kroki; data final_prep; merge veh_prep (in=a where=(percentage = 100)) par_prep (in=b); by key_id kroki count; if a and b; run; data final_merge; merge acc_prep (in=a) final_prep(in=b); by key_id kroki; if a and b; run; proc sql; create table want as select distinct kroki,key_id,accidenttime,acctype,accpoint,wlight,severity,publicdamage,accreasons,accidentangle,injurmajor,deaths,injminor, branchid,percentage,vehiclemake,vehiclemodel,vehiclecolor,accidentplace,age,partytype,healthstatus,nationality,InjNo,vehno,parno from final_merge order by kroki,key_id;
... View more