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.
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.