Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email DON';不发送重复的电子邮件(SAS)_Email_Sas - Fatal编程技术网

Email DON';不发送重复的电子邮件(SAS)

Email DON';不发送重复的电子邮件(SAS),email,sas,Email,Sas,我有下面的代码,检查表最后一次修改的时间,如果该日期等于今天,则将发送通知电子邮件。对于我正在监视的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 = 'c

我有下面的代码,检查表最后一次修改的时间,如果该日期等于今天,则将发送通知电子邮件。对于我正在监视的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计划程序)每小时运行一次

我想我需要记录下发送到某处的电子邮件。有人建议可以在我的数据集中使用布尔值或日期\电子邮件\发送字段

谁能给我提供一个例子代码,说明如何最好地实现这一点

非常感谢


亚伦

这里有一些值得思考的东西

/*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;

要监视多个表,只需对日志表进行排序,以便在合并中使用。

Petr的想法是可靠的。我以他的想法为基础,提出了以下建议

我建议创建永久性数据,其中存储发送邮件的人、已发送的人和日期:

data res_mails;
    input mail $;
    cards;
    'mail1' 
    'mail2' 
    'mail3'
;run;

data sent_mails;
    input date mail $;
    cards;  ;
ruN;
接下来,我们选择可以发送邮件的人。(==今天没有被派去的人。)我把触发条件留给你。(只需将category变量添加到res_mails表中即可。)


免责声明:未经测试

感谢您的回复,我正在尝试了解您的代码(应该提到我是SAS的新手),我正在尝试找出在哪里以及如何将我现有的代码合并到您的代码中???你能举个例子吗???有人能帮你编码吗?这不是复制粘贴类任务。您需要决定“日志”表的存储位置,您可能需要添加一些检查(例如,如果该表存在),等等。
%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;