Hello,
I wrote the following code, I would appreciate it if you could improve it for a shorter and more elegant writing.
The code's goal is to find all the records in the CM_EMAIL_SEND table whose emails are not in the CM_TEST_CUSTOMERS table. If records are found, they should be added from the CM_EMAIL_SEND table to the CM_EMAIL_CHASOM table, delete the records that were found from the CM_EMAIL_SEND table, SINUN field value should be changed to CM for records passed to the table CM_EMAIL_CHASOM. an email will be sent saying that records have been transferred between the 2 tables.
proc sql noprint;
create table AAA as
select t1.*
from CM_EMAIL_SEND t1
left join CM_TEST_CUSTOMERS t2
on lowcase(t1.email)=lowcase(t2.email)
where t2.email is null;
select count(*) into :row_count from AAA;
quit;
%put the number: &row_count;
%MACRO test;
%IF &row_count. gt 0 %THEN
%DO;
data CM_EMAIL_CHASOM;
set CM_EMAIL_CHASOM AAA(in=new);
if new then
SINUN= 'CM';
run;
proc sql;
delete from CM_EMAIL_SEND
where email in (select email from AAA);
quit;
%END;
%MEND test;
%test;
Thanks.
... View more