I hope this is not a very very obvious, but if it is please don't kill me, I'm really new at this and struggle to find much info.
This code should do the following:
-grab columns from 2 different tables -only select rows that are not on a third table on a particular date
proc sql;
create table DiallerExtra as
SELECT a.AGREEMENT_NUMBER,
b.CURRENT_FIRST_NAME,
b.TELEPHONE_NUMBER
FROM TABLE1 a, TABLE2 b
WHERE a.AGREEMENT_NUMBER
NOT IN (SELECT AgreementNumber
FROM TABLE3 (WHERE =(DeleteDate >= today()-1)))
;
quit;
I first tried this (below) and it worked fine to filter the results (I ended up with 15 rows only).
proc sql;
create table DiallerExtra as
SELECT a.AGREEMENT_NUMBER
FROM TABLE1 a
WHERE a.AGREEMENT_NUMBER
NOT IN (SELECT AgreementNumber
FROM TABLE3 (WHERE =(DeleteDate >= today()-1)))
;
quit;
But when I tried the first code, it doesn't seem to be filtering correctly cause it spits out all the agreements on TABLE2, which is a lot.
(WHERE =(DeleteDate >= today()-1))
. What does this do inproc sql
? It is not valid SQL syntax and I haven't come across it before. – Gordon Linoffwhere
condition. It prevents you from needing to create a subquery and instead will perform the filtering while reading the data. – Stu Sztukowski