Assuming you've got a base table and a lookup table for valid id's that both contain a variable ID then below code should work with minimal change.
data check;
if _n_=1 then
do;
/* create and populate in-memory hash lookup table with valid id's */
dcl hash h1(dataset:'work.valid_id');
h1.defineKey('id');
h1.defineDone();
end;
set work.base_table;
/* below condition becomes TRUE if ID exists in hash lookup table */
if h1.check()=0;
run;
... View more