BookmarkSubscribeRSS Feed
Eugenio211
Quartz | Level 8

Hello, hope everyone is alright.

 

I just want to ask if someone has a ready code on how to stop sending an email with attachment when there's error in the data steps, instead send an 'error' email to myself.

I have written the below code but it's not working.

 

%if &syscc=0 %then %do;
proc export data=Test_List
dbms=xlsx
replace
outfile='\\SAS_WIP\Test_List';
sheet='Sheet1';
run;

filename mymail email 'myemail@email.com'
from='myemail <myemail@email.com>'
subject='Test List'
attach=("\\SAS_WIP\Test_List.xlsx");

data _null_;
file mymail
to=('yourmail@email.com'
)
cc=('myemail@email.com');
run;
%end;

%else %do;
filename mymail email 'myemail@email.com'
from='InternalReports <myemail@email.com>'
subject='Test List';

data _null_;
file mymail
to=('myemail@email.com');
put "ERROR :(";
run;
%end;

 

Thanks a lot.

3 REPLIES 3
Quentin
Super User

Can you say more about what you mean by "not working"?  Is the macro sending the wrong email (if so, it could be that &syscc is not being set).  Or is your macro generating an error?  When you have an error in your main code, does SAS enter syntaxcheckmode (set obs=0)?  If so, than you may need to recover from syntaxcheckmode with something like:

 

%if %sysfunc(getoption(obs))=0 %then %do;
  options obs=max replace NoSyntaxCheck;
%end;

so that your data _null_ step will execute.

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Eugenio211
Quartz | Level 8
it's sending the error message even though there's no error in the data steps.
Quentin
Super User

Add %put &=syscc; before the code, to see what the value of SYSCC is.  Or turn on options SYMBOLGEN MLOGIC.  

 

Make sure you are using a new clean session when you test the code.  Some tools like DI studio will maintain a session across multiple submissions.  As a hack, you can %let syscc=0; at the top of your program to force it to start at 0.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 466 views
  • 0 likes
  • 2 in conversation