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

i want to send a mail as soon as it gets error on condition below

 

data _null_;

if nobs>0 then
do;
put 'ERROR: No of observations that need to be corrected are ' nobs ;
abort abend;
end;
stop;

set test;

run;

Mail should be sent out as nobs "need to be corrected based on test.xlsx file".

Can anyone help me with this

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

filename EMAIL email;
data_null_;
  if 0 then set TABLE nobs=NOBS;
  if NOBS>1 then do;
    file MAIL to      = 'user@company.com'
              subject = 'Error Mail message';
    put "Hello";
    put "We have a problem";  
  end;
  stop;
run;

 

 

 

 

 

View solution in original post

9 REPLIES 9
Kurt_Bremser
Super User

@Son_Of_Krypton wrote:

i want to send a mail as soon as it gets error on condition below

 

data _null_;

if nobs>0 then
do;
put 'ERROR: No of observations that need to be corrected are ' nobs ;
abort abend;
end;
stop;

set test;

run;

Mail should be sent out as nobs "need to be corrected based on test.xlsx file".

Can anyone help me with this


nobs will always be missing at the beginning of the data step, so your condition can never be true. Did you actually want to send the mail depending on the number of observations in dataset test, and not on a variable called nobs in that dataset?

Son_Of_Krypton
Fluorite | Level 6

scenario is like if table has more than one record then it should fail and mail should be sent.as i mentioned ignore nobs then

Kurt_Bremser
Super User

Then you need the NOBS= option in the SET statement:

data _null_;
if nobs > 1
then do;
  put 'ERROR: No of observations that need to be corrected are ' nobs ;
  abort abend;
end;
stop;
set test nobs=nobs;
run;
ChrisNZ
Tourmaline | Level 20

Like this?

filename EMAIL email;
data_null_;
  if 0 then set TABLE nobs=NOBS;
  if NOBS>1 then do;
    file MAIL to      = 'user@company.com'
              subject = 'Error Mail message';
    put "Hello";
    put "We have a problem";  
  end;
  stop;
run;

 

 

 

 

 

Son_Of_Krypton
Fluorite | Level 6

program also need to be aborted

ChrisNZ
Tourmaline | Level 20

Surely you can add that.

And the proper email content.

Son_Of_Krypton
Fluorite | Level 6

I am getting below error:

 

filename EMAIL email;

data  _null_;
3834 if 0 then set TEST nobs=NOBS;
3835 if NOBS>1 then do;
3836 file MAIL to = 'user@company.com'
^
ERROR: Option "to" is not known for FILE
3837 subject = 'Error Mail message';
3838 put "Hello";
3839 put "We have a problem";
3840 put "Error: Records not matching" ;
3841 end;
3842 stop;
3843 run;

ChrisNZ
Tourmaline | Level 20

Apologies for the botched email syntax and glad you could solve your question.

I copied without thinking from the first source I found.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 2581 views
  • 1 like
  • 3 in conversation