BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sourav_sas
Quartz | Level 8

Hi

I need one small help. I want to read one specific error from the SAS LOG. In respect of that error I want to send mail to USER. I can read all errors or if any error comes in LOG by &SYSERR or &SYSERRORTEXT and send mail also. But not able to read specific error there I can mention the error.

I am showing the code for example,

filename myfile email                                                                                                                   
to= "xxx.xxxxxx@xxxx.xxx"                                                                                                               
subject= "Error in Report"                                                                                                              
type= "text/plain"
importance="HIGH";
 

%macro errmail;                                                                                                                        
 /*%if &syserrortext = "Statement is not valid or it is used out of proper order." %then %do; */                                                                                                          
  data _null_;                                                                                                                          
   file myfile;                                                                                                                         
   put 'Your job received the following ERROR/WARNING message:';                                                                        
   put;                                                                                                                                 
   put 'ERROR was:';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put;                                                                                                                                 
   put 'WARNING was:';                                                                                                                  
   put "&syswarningtext";                                                                                                               
  run;                                                                                                                                  
 %end;                                                                                                                                  
%mend errmail;                                                                                                                          
                                                                                                                                        
data one;                                                                                                                               
 a;                                                                                                                                     
run;  

%put &syserr; or %put &syserrortext;

/*"ERROR 180-322: Statement is not valid or it is used out of proper order.";*/
/*I need to mention the above error specifically*/
/*I need to send mail only for this error not for all error*/
 
                                                                                                                                        
%errmail;



Here I need to mention the error details to send mail on when that error will come, not for every error.

 

Please help me on this situation, if there is any macro variable to use or any code.

Thanks

 

Regards

Sourav

1 ACCEPTED SOLUTION
28 REPLIES 28
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Are you putting this in the code which creates the error?  syserr and syslog and such like only hold the information for the last error, and may be cleared at certain points.  Your code should be robust enough to not generate errors or warnings (hence the whole testing process) and should capture problems itself:

https://en.wikipedia.org/wiki/Defensive_programming

 

Hence if you want to capture an error where dataset is missing, your code would have a handler at the beginning of the code to check this, and only proceed if the dataset is present, and would throw out an email notification if missing. 

 

You could do it post hoc, but then you need to read in and parse the log, check the various things in combination - for instance a warning might lead to an error or series of errors etc.

Sourav_sas
Quartz | Level 8

Hey,

Thanks for your advice. Error is due to space issue. and the space issue we can not fix. For that I am saying only for that error I need to send mail to user, the error is like "

ERROR 180-322: Statement is not valid or it is used out of proper order."

This error details I need to mention to code, respect to this I will get mail.

Only for this error, not for any other error.

Is there any way that I can do that. Any macro, or any short code?

like IF the ERROR "as mentioned above" THEN mail will be sent.

 

Thanks

 

Regards

Sourav

RW9
Diamond | Level 26 RW9
Diamond | Level 26

"Error is due to space issue" - ??  do you mean physical disk space?  If so do a pre-check for how many observations and estimate it, or increase workspace.  Unless your talking Tb not sure thats a reason.  Anyways you would need to capture it at the time it happens, or by scanning a log.  There isn't a special fix my process bit of code we can supply.

Kurt_Bremser
Super User

180-322 is the typical syntax error for wrongly written code, and has nothing to do with space issues. These look completely different.

 

You should really work at improving your code to make it robust in the first place. Informing people that you are unable to write working code is not helpful.

Sourav_sas
Quartz | Level 8

Hi thanks for the help. But I know that the code is wrong, I am intentionally creating error. But I want to send mail respective of these error. That is my concern. Is there any way I can do that? Please help me on that. Instead of error code if I want to mention the error test then how would I do that in a macro, that is my point. This is user choice, they want like this, I need to follow that, so please help me on this.

Simply in case of specific error like above mentioned How can I send mail to user or any mail ID.

 

 

Thanks

 

Regards

Sourav

Kurt_Bremser
Super User

@Sourav_sas wrote:

Hi thanks for the help. But I know that the code is wrong, I am intentionally creating error. But I want to send mail respective of these error. That is my concern. Is there any way I can do that? Please help me on that. Instead of error code if I want to mention the error test then how would I do that in a macro, that is my point. This is user choice, they want like this, I need to follow that, so please help me on this.

Simply in case of specific error like above mentioned How can I send mail to user or any mail ID.

 

 

Thanks

 

Regards

Sourav


Sorry, but I don't get it. If you are intentionally creating an error, you know the condition for the mail in the first place, so just send it there. No need to complicate things unnecessarily.

Sourav_sas
Quartz | Level 8

Exactly. I am getting mail, fine. But I want to get mail respect to one specified error. Right now using &SYSERR and &SYSERRORTEXT I am getting mail when any error showing in the SAS Log,

so is there any way where I can make one condition there I will mention the error text and will get mail respect to that error only, not for all error.

 

Appreciate your effort. Thanks for your valuable feedback.

 

Regards

Sourav

Kurt_Bremser
Super User

Why are you insisting on that wasteful detour with the ERROR? Show where you detect the condition in the code, and we'll help you send the email there, if that's a problem.

Sourav_sas
Quartz | Level 8

In my sample code I am using wrong code as

data one;                                                                                                                               
 a;                                                                                                                                     
run; 

to get error.

%macro errmail;                                                                                                                        
  data _null_;                                                                                                                          
   file myfile;                                                                                                                         
   put 'Your job received the following ERROR/WARNING message:';                                                                        
   put;                                                                                                                                 
   put 'ERROR was:';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put;                                                                                                                                 
   put 'WARNING was:';                                                                                                                  
   put "&syswarningtext";                                                                                                               
  run;                                                                                                                                  
 %end;                                                                                                                                  
%mend errmail;   
data one;                                                                                                                               
 a;                                                                                                                                     
run;  

/*%put &syserr; or %put &syserrortext;*/ 
                                                                                                                        
%errmail; 

 

 

Entire code mentioned in the above, you can see there.

I am using this part to get mail as you can see

Filename myfile email                                                                                                                   
to= "xxx.xxxx@xxx.xxx"                                                                                                               
subject= "Error in Report"                                                                                                              
type= "text/plain"
importance="HIGH";

Now in the section where error should be mentioned specifically, there I am using generic condition as

%macro errmail;                                                                                                                        
  data _null_;                                                                                                                          
   file myfile;                                                                                                                         
   put 'Your job received the following ERROR/WARNING message:';                                                                        
   put;                                                                                                                                 
   put 'ERROR was:';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put;                                                                                                                                 
   put 'WARNING was:';                                                                                                                  
   put "&syswarningtext";                                                                                                               
  run;                                                                                                                                  
 %end;                                                                                                                                  
%mend errmail;                                                                                                                          
                                                                                                                                        
data one;                                                                                                                               
 a;                                                                                                                                     
run;  

/*%put &syserr; or %put &syserrortext;*/ 
                                                                                                                                        
%errmail;

 

 

But here instead of %put I want to use like

%macro errmail;                                                                                                                        
 %if "&syserrortext" is "Statement is not valid or it is used out of proper order." %then %do;
  data _null_;                                                                                                                          
   file myfile;                                                                                                                         
   put 'Your job received the following ERROR/WARNING message:';                                                                        
   put;                                                                                                                                 
   put 'ERROR was:';                                                                                                                    
   put "&syserrortext";                                                                                                                 
   put;                                                                                                                                 
   put 'WARNING was:';                                                                                                                  
   put "&syswarningtext";                                                                                                               
  run;                                                                                                                                  
 %end;                                                                                                                                  
%mend errmail;                                                                                                                          
                                                                                                                                        
data one;                                                                                                                               
 a;                                                                                                                                     
run;  

/*%put &syserr; or %put &syserrortext;*/

/*"ERROR 180-322: Statement is not valid or it is used out of proper order.";*/
/*I need to mention the above error specifically*/
/*I need to send mail only for this error not for all error*/
 
                                                                                                                                        
%errmail;

The condition should be specific not generic. I want to get mail in respect to only one error. I am using this error for example.

 

Sourav_sas
Quartz | Level 8

This error text might be variable. I can use other error from the log in future also.

I need some sort of condition where I can use the error text for condition to get mail.

Hope this time you will again help me like previous case.

 

Thanks

 

Regards

Sourav

Sourav_sas
Quartz | Level 8

Hi Kurt,

 

I am looking for the solution still now. If any way will found. Please let me know.

 

Thanks

 

Regards

Sourav

Kurt_Bremser
Super User

I have already given you enough hints how to do the right thing. I will not waste my (and your) time by aiding you in doing something extremely stupid.


@Sourav_sas wrote:

Hi Kurt,

 

I am looking for the solution still now. If any way will found. Please let me know.

 

Thanks

 

Regards

Sourav


 

AlanC
Barite | Level 11

I have ripped the sas log to pieces and have a parser that works great. That is my background.

 

Use a regular expression and parse the log. Minor issue. It is easy to capture the error and the code that generated it.

 

Your error regex (in C#):

 

        internal static string rxError { get { return @"^ERROR:\s([\d\D]+?)(?=\r)"; } }

 

Code this in SAS and you can find whatever you need. I recommend RegexBuddy if you will do a lot of regex.

 

https://github.com/savian-net
Kurt_Bremser
Super User

Just look at the possible values in &syserr. It will jump into your eyes so hard it actually hurts (from the documentation I linked to):

SYSERR Values
Value
Description
0
Execution completed successfully and without warning messages.
1
Execution was canceled by a user with a RUN CANCEL statement.
2
Execution was canceled by a user with an ATTN or BREAK command.
3
An error in a program run in batch or non-interactive mode caused SAS to enter syntax-check mode.
4
Execution completed successfully but with warning messages.
5
Execution was canceled by a user with an ABORT CANCEL statement.
6
Execution was canceled by a user with an ABORT CANCEL FILE statement.
>6
An error occurred. The value returned is procedure-dependent.
The following table contains warning return codes. The codes do not indicate any specific problems. These codes are guidelines to identify the nature of a problem.
SYSERR Warning Codes
Warning Code
Description
108
Problem with one or more BY groups
112
Error with one or more BY groups
116
Memory problems with one or more BY groups
120
I/O problems with one or more BY groups
The following table contains error return codes. The codes do not indicate any specific problems. These codes are guidelines to identify the nature of a problem.
SYSERR Error Codes
Error Code
Description
1008
General data problem
1012
General error condition
1016
Out-of-memory condition
1020
I/O problem
2000
Semantic action problem
2001
Attribute processing problem
3000
Syntax error
4000
Not a valid procedure
9999
Bug in the procedure
20000
A step was stopped or an ABORT statement was issued.
20001
An ABORT RETURN statement was issued.
20002
An ABORT ABEND statement was issued.
25000
Severe system error. The system cannot initialize or continue.

 

Never will there be any longer text like the one you used in the comparison.

You REALLY have to start reading the documentation, or you'll be damned to commit such very obvious mistakes time and again.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 28 replies
  • 5475 views
  • 4 likes
  • 5 in conversation