1

I have a code that tells me that something went wrong in a file 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

I use %include function for that in an another file, but when I have there:

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";

and if error is here (before %include function) I don't get an e-mail then. Can I use the %include function if I want to get a information about the error which is before this function?

Below is part of the log, so I have an error earlier and the part of the include function is not done.

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
aola
  • 87
  • 3
  • 8
  • Can you show the log from one of your test runs that has an error and does not generate an email? Note that the value of &syserr is reset after every step boundary, which means your sample code could only detect an error in the PROC APPEND step. Also note that if SAS errors and enters syntaxcheck mode (sets obs=0), your email will not be sent unless you recover from syntaxcheck mode. – Quentin May 09 '16 at 23:29
  • It would be help if the macro %errmail to put in the code in the same file? How can I recover it from syntaxcheck mode? – aola May 10 '16 at 14:43
  • 1
    In the macro before the data _null_ step, add `options obs=max replace nosyntaxcheck;` That should recover from syntaxcheck mode. When you're in syntaxccheck mode, SAS sets obs=0 (as in the note in your log) so data step code does not execute. – Quentin May 10 '16 at 15:25
  • yes, you right, thank you, it's working – aola May 11 '16 at 08:37

2 Answers2

3

Note that the &SYSERR variable is reset after every step, so as written, this will only detect whether an error occurs in the PROC APPEND step that immediately precedes the %INCLUDE statement.

That said, as seen in the log, if PROC APPEND errors it may make SAS enter SYNTAXCHECK mode. See the note that SAS set option obs=0. In this state, no code is executed, SAS simply checks code for compilation errors.

If you want to recover from SYNTAXCHECK mode, so that SAS will continue executing code that occurs after the error, you could add the following OPTIONS statement to your %ERRMAIL macro, before the data _null_ step:

options obs=max replace nosyntaxcheck;
Quentin
  • 5,960
  • 1
  • 13
  • 21
0

Your proc append has an extra semi column in it:

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

Should be:

 proc append BASE=abc.my_table DATA=load_a. FORCE; 
dannmate
  • 106
  • 3
  • 12