If appears that within each clusterid, you data is sorted by joblevel. So if the desired result for V1 is produced within a given job level, then V1 is finished, and subsequent job levels should not be used. Same for V2. The program below nests of loop over each joblevel within its clusterid. It
At the end of processing the clusterid, it copies result values back to the original vars, ready for output.
At the end of each joblevel, if the result is non-missing it declare that variable as finished.
For every record in every subsequent joblevel, if a variable is marked finished, it is not processed further
The CONTINUE statement tells the loop to skip directly to the next iteration, so that one var may be marked finished, but the other var is still processed.
data want (drop=result: finished: I);
do until (last.clusterid);
do until (last.joblevel);
set a;
by clusterid joblevel;
array v{2} v1 v2;
array result{2};
array finished{2};
do I=1 to 2;
if finished{I}=1 then continue;
if v{I}=1 then result{I}=1;
else if result{I}=. then result{I}=v{I};
end;
end;
do I=1 to 2;
if not(missing(result{I})) then finished{I}=1;
end;
end;
do I=1 to 2;
v{I}=result{I};
end;
put (clusterid joblevel v1 v2) (:);
run;
Regards,
Mark
... View more