Hi @GS2,
Try this:
/* Create test data for demonstration */
data have;
input enc code;
cards;
1 3
1 2
1 2
1 4
2 2
2 4
2 3
2 1
2 5
3 22
3 1
3 1
4 1
4 0
4 2
;
/* Select encounters with both code 1 and code 2 */
data want(drop=_:);
do until(last.enc);
set have;
by enc;
if code=1 then _c1=1;
else if code=2 then _c2=1;
end;
do until(last.enc);
set have;
by enc;
if _c1 & _c2 then output;
end;
run;
If you don't need all observations from the selected encounters, but just their numbers, replace the entire second DO loop by a subsetting IF statement:
if _c1 & _c2;
and change drop=_: to keep=enc.
... View more