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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at 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.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

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