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
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 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?
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
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;
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;
program also need to be aborted
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;
Specify the EMAIL file reference in a separate FILENAME Statement, EMAIL (SMTP) Access Method, and study the documentation I linked to.
Apologies for the botched email syntax and glad you could solve your question.
I copied without thinking from the first source I found.
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!
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.