我有以下代码检查上次修改表的时间,如果该日期等于今天,则会发送通知电子邮件。对于我正在监控的3个不同的表,我有这个代码x3。
filename myemail EMAIL
to="john.doe@test.com"
cc=""
from="me.myself@test.com"
;
data _null_;
file myemail;
if _n_=1 and eof then put '!EM_ABBORT!';
set test end=eof;
where (memname = 'class' and datepart(modate) = date());
put "Hello";
put" ";
put"This is a test email";
put" ";
put memname= ;
put modate= ;
put" ";
put"Many thanks";
run;
我遇到的问题是,一旦符合标准并且已发送电子邮件(已通知此人),我不希望下次代码运行时再次发送相同的电子邮件,因为他们已经收到有关该特定信息的通知表。计划的代码(Windows Scheduler)每小时运行一次。
我相信我需要记录某处发送的电子邮件。有人建议可以在我的数据集中使用boolean或date_email_sent字段来完成。
任何人都可以提供一个示例代码,了解如何实现这一目标的最佳方式???
非常感谢
亚伦
答案 0 :(得分:0)
这里有一些值得思考的东西。
/*tab1 is the table we want to monitor for a change*/
data tab1;
col1='a';
run;
/*initial load of log_table - this table contains the last modified date of the table(s) we monitor*/
proc contents noprint data=tab1 out=columns(keep=libname memname modate);quit;
proc sql;
create table log_table as
select distinct *
from columns
;quit;
/*wait a second*/
%let rc = %sysfunc(sleep(1));
/*now we update tab1*/
proc sql;
insert into tab1 values ('b')
;quit;
/*check when tab1 was last modified*/
proc contents noprint data=tab1 out=columns(keep=libname memname modate);quit;
proc sql;
create table last_modate as
select distinct
libname
,memname
,modate as new_modate
from columns
;quit;
/*and compare the current modate with modate from the last run*/
data log_table(drop=new_modate);
merge log_table (in=a)
last_modate (in=b);
by libname memname;
if modate ne new_modate then do;
/*check other conditions, send an email, ...*/
modate = new_modate;
end;
run;
要监视多个表,只需保持log_table已排序,以便可以在合并中使用。
答案 1 :(得分:0)
我建议制作永久数据,存储发送邮件的人以及发送者和日期:
data res_mails;
input mail $;
cards;
'mail1'
'mail2'
'mail3'
;run;
data sent_mails;
input date mail $;
cards; ;
ruN;
接下来,我们选择您可以发送邮件的人。 (==今天还没有发送过。)我将触发条件留给你。 (只需将类别变量添加到res_mails表。)
%macro select_and_update_recipiants;
proc sql; /*the selection bit*/
select distinct(mail) into: respList separated by ' '
from res_mail
where mail not in (
select( select distinct(mail) from sent_mails
where date=date();
)
)
quit;
/*The update bit. Go through the mails that will be sent and add them to list that have been sent.*/
data sent_mails;
set sent_mail;
%for i=1 %to %sysfunc(countw(&SYSPARM.,' '));
date=date();
mail=%scan(&repList.,&i,' ');
output;
%end;
%mend;
%sendMail_to_resplist;
免责声明:未经测试。