data check;
set file1;
if _n_ = 1
then do;
declare hash f2 (dataset:"file2");
f2.definekey('prsnid');
f2.definedone();
end;
if f2.check() ne 0; /* indicates "not found" */
run;
Use a hash object.
For code examples, supply example data in usable form (data steps with datalines), so we have something to develop and test against.
This code will return 13, which is in file1, but not file2.
data file1;
input prsnid $ ;
datalines;
11
12
13
14
;
run;
data file2;
input prsnid $ gracedate yymmdd10.;
datalines;
11 2020-12-31
12 2020-12-31
14 2020-01-01
;
run;
proc sql;
select prsnid
from file1
except
select prsnid
from file2
;
quit;
data check;
set file1;
if _n_ = 1
then do;
declare hash f2 (dataset:"file2");
f2.definekey('prsnid');
f2.definedone();
end;
if f2.check() ne 0; /* indicates "not found" */
run;
You can have multiple hash objects in your data step. The limiting factor is the memory available vs. the size of the objects (variable(s) size * number of items + overhead for building the btree).
Each "lookup" dataset will have its own object with its own methods (f3.check(), f4.check(), and so on).
If I understand your question, you can use the EXCEPT operator in PROC SQL. It will display values of a variable that are present in the first data set, but not in the second data set. Here is some code to test.
data one;
input num;
cards;
1
2
3
4
;
run;
data two;
input num;
cards;
1
2
6
7
;
run;
proc sql;
select num
from one
except
select num
from two
;
quit;
The final result will display 3 and 4.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.