Thank you very much for the suggestion! I definitly have to read up on hash objects. One problem: data have;
length col1 $ 1 col2 3 col3 $ 3 col4 $ 3;
infile datalines delimiter=',';
A,1,
A,2,foo
A,3,
B,1,bar
B,2,
B,1,
B,2,foo
C,1,
C,2,bar
C,3,
C,4,
C,3, /* new */
C,2, /* new */
C,3,
C,4,
D,1,
D,2,
D,3,
;
run;
data lookup;
set have(drop=col4 rename=(col3=col4));
where not missing(col4);
run;
data want;
set have;
if _n_ = 1 then do;
declare hash h(dataset: 'lookup');
h.defineKey('col1', 'col2');
h.defineData('col4');
h.defineDone();
end;
if not missing(col3) then do;
col4 = col3;
end;
else do;
rc = h.find(key: col1, key: col2-1);
rc = h.ref();
end;
drop rc;
run; I've inserted two new observations. Expected result: OBS col1 col2 col3 col4 1 A 1 2 A 2 foo foo 3 A 3 foo 4 B 1 bar bar 5 B 2 bar 6 B 1 7 B 2 foo foo 8 C 1 9 C 2 bar bar 10 C 3 bar 11 C 4 bar 12 C 3 bar 13 C 2 14 C 3 15 C 4 16 D 1 17 D 2 18 D 3 Actual result: OBS col1 col2 col3 col4 1 A 1 2 A 2 foo foo 3 A 3 foo 4 B 1 bar bar 5 B 2 bar 6 B 1 7 B 2 foo foo 8 C 1 9 C 2 bar bar 10 C 3 bar 11 C 4 bar 12 C 3 bar 13 C 2 14 C 3 bar 15 C 4 bar 16 D 1 17 D 2 18 D 3 Observations 14 und 15 meet the criteria so they inherit the value. But hierarchically they belong to observation 13 which doesn't have an associated value. Is there a way to consider this?
... View more