1

我有一个代码告诉我文件 a.sas 出了点问题

filename myfile email                                                                                                                   
to=&e_mail.                                                                                                               
subject= "Error"                                                                                                              
type="text/plain";                                                                                                                      

%macro errmail;                                                                                                                         
 %if &syserr ne 0 %then %do;                                                                                                            
  data _null_;                                                                                                                          
   file myfile;                                                                                                                                                                                               
   put;                                                                                                                                 
   put 'ERROR';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put;
    put "Log: \\logs" ;
  run;                                                                                                                                  
 %end;                                                                                                                                  
%mend errmail;                                                                                                                          


%errmail

我在另一个文件中使用 %include 函数,但是当我在那里时:

data a;
infile "/usr/local/abc/load_file" dlm='09'x firstobs=2;
INPUT id age;
run;

PROC SORT DATA=_load_a. NODUPKEY;
 BY id;

  proc sql noprint;
delete from abc.my_table;
quit;

proc append BASE=abc.my_table; DATA=load_a. FORCE; 

%include "/usr/local/abc/a.sas";

如果出现错误(在 %include 函数之前),那么我不会收到电子邮件。如果我想获取有关此函数之前的错误的信息,我可以使用 %include 函数吗?

下面是日志的一部分,所以我之前有一个错误并且包含函数的部分没有完成。

NOTE: 129 records were read from the infile "/usr/local/642.txt".
      The minimum record length was 25.
      The maximum record length was 25.
NOTE: The data set WORK.LOAD_642 has 129 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds



16         PROC SORT DATA=LOAD_&nr. NODUPKEY;
17          BY ID;
3                                                            System SAS                                  08:15 Tuesday, May 10, 2016


NOTE: There were 129 observations read from the data set WORK.LOAD_642.
NOTE: 0 observations with duplicate key values were deleted.
NOTE: The data set WORK.LOAD_642 has 129 observations and 3 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


19           proc sql noprint;
20         delete from a.642_ID;
sasxdbi: dbicon: special image for SAS/Poland
sasxdbi: dbicon: special image for SAS/Poland
NOTE: 135 rows were deleted from a.642_ID.

20       !                                              ;
21         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           17.44 seconds
      cpu time            0.08 seconds


22  
23         proc append BASE=a.642_ID;
sasxdbi: dbicon: special image for SAS/Poland
23       !                                                    DATA=LOAD_&nr. FORCE;
                                                              ____
                                                              180
ERROR 180-322: Statement is not valid or it is used out of proper order.
24         
25         %include "/usr/local/generic.sas";

NOTE: Statements not processed because of errors noted above.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. This might cause NOTE: No observations in data set.
NOTE: PROCEDURE APPEND used (Total process time):
      real time           1.20 seconds
      cpu time            0.07 seconds




NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
4

2 回答 2

3

请注意,&SYSERR 变量在每一步之后都会被重置,因此按照所写,这将仅检测在紧接 %INCLUDE 语句之前的 PROC APPEND 步骤中是否发生错误。

也就是说,如日志中所见,如果 PROC APPEND 错误可能会使 SAS 进入 SYNTAXCHECK 模式。请参阅 SAS 设置选项 obs=0 的注释。在这种状态下,不执行任何代码,SAS 只是检查代码是否存在编译错误。

如果您想从 SYNTAXCHECK 模式中恢复,以便 SAS 继续执行错误后发生的代码,您可以在data _null_步骤之前将以下 OPTIONS 语句添加到您的 %ERRMAIL 宏中:

options obs=max replace nosyntaxcheck;
于 2016-05-11T22:07:08.530 回答
0

您的 proc append 中有一个额外的 semi 列:

 proc append BASE=abc.my_table; DATA=load_a. FORCE; 

应该:

 proc append BASE=abc.my_table DATA=load_a. FORCE; 
于 2016-05-11T07:02:45.690 回答