0

我是一个没有经验的 SAS Data Integration Studio 用户。

我想收到有关工作状态的电子邮件信息。使用“状态处理”和操作“发送电子邮件”(来自工作选项)对我来说并不令人满意。首先 - (可能?)我无法将日志附加到这封电子邮件。

在 SAS Enterprise Guide 中,我开发并测试了用于发送电子邮件的代码,其中包含登录附件和邮件正文中的一些有用信息(日期时间、错误列表):

%let mail = "test@test.com";
%let path_error = /home/ ... .log;

filename msg email
 to =           (&maile)
 subject =      "SAS Message Test"
 attach =       "&path_error.";

data _null_;
 dttm = put(datetime(),nldatm.);

 infile "&path_error.";
 input;

 file msg;
 if _n_ = 1 then do;
    put "Date time: " dttm;
    put;
    put "Full log in attach.";
    put "There are some ERRORs and WARNINGs:";
    put;
    end;
 if substr(_infile_,1,5) = "ERROR" then 
    put _infile_;
 if substr(_infile_,1,7) = "WARNING" then 
    put _infile_;
run;

此代码工作正常 - 我收到带有错误和警告列表的完整邮件。在日志中我可以看到:

NOTE: 268 records were read from the infile "[...].log"

但是如何在 DIS 中实现这段代码(尤其是通过 infile 语句读取)?

我修改了工作选项:

  1. Precode - 将日志放入外部文件;日志名称包含作业名和日期时间:
%let path = /home/[...]/log_&etls_jobName._%sysfunc(datetime(), datetime.).log; 
proc printto log="&path.";
run;
  1. 邮政编码 - 我使用了企业指南中的代码:
%let address = "test@test.com";
%let message = problems with &etls_jobName;

         filename sendMail email 
                to=         (&address) 
                subject=        "ETL Process problem: &etls_jobName." 
                attach=     "&path."; 

            options nosyntaxcheck;  

         data _null_; 
            dttm = put(datetime(),nldatm.);

                infile "&path.";
                input;

                file sendMail; 
                 if _n_ = 1 then do;
                    put "Date time: " dttm;
                    put;
                    put "Full log in attach.";
                    put "There are some ERRORs and WARNINGs:";
                    put;
                    end;
                 if substr(_infile_,1,5) = "ERROR" then 
                    put _infile_;
                 if substr(_infile_,1,7) = "WARNING" then 
                    put _infile_;
         run; 

实际上,我收到了带有登录附件的电子邮件,但正文为空。在附加的日志中,我可以看到:

NOTE: 0 records were read from the infile 

我有一些问题:

  1. 为什么0条记录???
  2. 当我从 Postcode 中删除input;语句并运行作业时,我收到电子邮件,正文中包含“日期时间/完整登录附件/存在一些错误和警告”。为什么它们input在代码中起作用的地方被删除?
  3. options nosyntaxcheck;没有代码就不会发送电子邮件。为什么?

感谢您的回答。问候,米哈乌

4

1 回答 1

0

数据步骤停止的正常方式是当它读取超过输入的末尾时(读取原始数据或访问数据集)。

因此,将您的 _N_=1 块移动到 INPUT 语句之前。您可能想要更改有关错误和警告的消息的措辞。或者等到知道有记录要读取后再写。

%let address = "test@test.com";
%let message = problems with &etls_jobName;

filename sendMail email 
  to=(&address) 
  subject="ETL Process problem: &etls_jobName." 
  attach="&path."
; 

options nosyntaxcheck;  

data _null_; 
  dttm = put(datetime(),nldatm.);

  file sendMail; 
  if _n_ = 1 then do;
    put "Date time: " dttm;
    put;
    put "Full log in attach.";
    put "There are some ERRORs and WARNINGs:";
    put;
  end;

  infile "&path.";
  input;
  if _n_ = 1 then do;
    put "There are some ERRORs and WARNINGs:";
    put;
  end;
  if substr(_infile_,1,5) = "ERROR" then put _infile_;
  if substr(_infile_,1,7) = "WARNING" then put _infile_;
run; 
于 2022-01-28T15:11:12.257 回答