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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1864 views
  • 1 like
  • 3 in conversation