1

Although I have the error handling:

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

%macro errmail;                                                                                                                         
 %if &syserr ne 0 %then %do;  
 options obs= max replace nosyntaxcheck; 
  data _null_;        
   file myfile;                                                                                                                                                                                               
   put;                                                                                                                                 
   put 'ERROR';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put 'check a log'
  run;       
 %abort cancel;  
 %end;                                                                                                                                  
%mend errmail;

when I have the error in the proc export: (&number. is the table in the work)

proc export data=&number.
outfile="/usr/local/backup/&number./&number._%SYSFUNC(TODAY(),DATE9.).txt"
replace
dbms=dlm; 
delimiter=';';
 run;
 %errmail;

ERROR: Physical file does not exist, /usr/local/backup/2116/2116_13MAY2016.txt.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.2116.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

SAS dosen't check a macro and doesn't send an e-mail. I have an error in the path, so I understand the error, but I need an e-mail about that and I want that SAS stops processing because of macro. Adding some options to the macro can fix it?

aola
  • 87
  • 3
  • 8
  • What happens if you add %PUT &syserr; after the PROC EXPORT step? My guess is it isn't setting &syserr to a nonzero value. – Quentin May 13 '16 at 13:27
  • I agree. `PROC IMPORT` and `PROC EXPORT` have some issues setting `&SYSERR` properly. Rely perhaps on `&SYSERRTEXT` instead (which does get set properly). – Joe May 13 '16 at 13:51
  • Sholud I change `&syserr ne 0`? for syserrtext? But if &syserr=0 for proc export why SAS stops although I have the nosyntaxcheck option? – aola May 13 '16 at 14:51
  • In case you are interested, there are alternative ways to send emails when errors occur in SAS. See this question: http://stackoverflow.com/questions/9535843/sas-email-if-errors-occur/9539188#9539188 – Robert Penridge May 13 '16 at 15:01

1 Answers1

0

this is how I send out my email from SAS

not required to create a file on the system

filename outbox email "email@address.com"; 
data _null_;    
file outbox    
to=("email@address.com")     
cc=("email@address.com")    
subject="SUBJECT OF EMAIL "    
/* attach=("C:\sas\results.out" "C:\sas\code.sas")  */    ; /* incase you need to attach a file */    
put 'Hello! ';    
put ' '; 
put 'Thank you & let me know if there is anything,';
put "&macrovar.";   /*in case you need to put some detail in the email from macro variables   make sure to use double quote for that */
put 'SIGNATURE ME'; 
run;
Wired604
  • 370
  • 1
  • 3
  • 10