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.

 

 

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 298 views
  • 0 likes
  • 2 in conversation