Thanks so much. But this does not work. If you notice for ID = A at 9:30:00 SELLORNUM 20000199 is paired with two BUYORNUM 20000196 and 200197. So this is not the desired output. @ChrisNZ wrote: Like this? data O;
input (ID Type BorS ORNUM Time )(:$);
cards;
A O B 20000196 9:30:00
A O B 20000197 9:30:00
A O S 20000199 9:30:00
A O B 20000201 9:30:00
A O B 20000205 9:30:01
A O S 20000209 9:30:01
B O B 20000531 9:30:00
B O S 20000643 9:30:00
B O B 20000754 9:30:01
run;
data T;
input (ID Type BUYORNUM SELLORNUM TNUM Time )(:$);
cards;
A T 20000196 20000199 10001 9:30:00
A T 20000197 20000199 10002 9:30:00
A T 20000205 20000209 10004 9:30:01
B T 20000754 20000643 10010 9:30:01
run;
data WANT;
set O;
if _N_=1 then do;
dcl hash BUY(dataset:'T');
BUY.definekey('BUYORNUM');
BUY.definedata(all:'Y');
BUY.definedone();
dcl hash SELL(dataset:'T');
SELL.definekey('SELLORNUM');
SELL.definedata(all:'Y');
SELL.definedone();
if 0 then set T;
end;
call missing( BUYORNUM, SELLORNUM, TNUM );
output;
RC=BUY.find(key:ORNUM);
if RC=0 then do;
output;
RC=BUY.remove();
RC=SELL.remove(key:SELLORNUM);
end;
else do;
RC=SELL.find(key:ORNUM);
if RC=0 then do;
output;
RC=SELL.remove();
RC=BUY.remove(key:BUYORNUM);
end;
end;
drop RC;
run; ID Type BorS ORNUM Time BUYORNUM SELLORNUM TNUM A O B 20000196 9:30:00 A T B 20000196 9:30:00 20000196 20000199 10001 A O B 20000197 9:30:00 A T B 20000197 9:30:00 20000197 20000199 10002 A O S 20000199 9:30:00 A O B 20000201 9:30:00 A O B 20000205 9:30:01 A T B 20000205 9:30:01 20000205 20000209 10004 A O S 20000209 9:30:01 B O B 20000531 9:30:00 B O S 20000643 9:30:00 B T S 20000643 9:30:01 20000754 20000643 10010 B O B 20000754 9:30:01 B T B 20000754 9:30:01 20000754 20000643 10010
... View more