data Group_A; input set units; cards; 1 5 2 6 3 258 ; data Group_B; input set units; cards; 1 4 2 8 3 12 5 5 ; data Group_C; input set units; cards; 1 3 2 4 3 16 4 8 ; run; proc sql; create table sets as select coalesce(d.set,c.set) as set from (select coalesce(a.set,b.set) as set from group_A a inner join group_B b on a.set=b.set) d inner join group_C c on d.set=c.set; quit; data want; if 0 then set group_A group_B group_C; if _n_=1 then do; declare hash h_a(dataset:'group_A'); h_a.definekey('set'); h_a.definedata('set','units'); h_a.definedone(); declare hash h_b(dataset:'group_B'); h_b.definekey('set'); h_b.definedata('set','units'); h_b.definedone(); declare hash h_c(dataset:'group_C'); h_c.definekey('set'); h_c.definedata('set','units'); h_c.definedone(); end; count=0; do until (last); set sets end=last; retain count; h_a.find();; count+units; if count>300 then leave; else output; h_b.find(); count+units; if count>300 then leave; else output; h_c.find(); count+units; if count>300 then leave; else output; end; run;
... View more