BookmarkSubscribeRSS Feed
SASdn
Obsidian | Level 7

Hi all

 

I have the following code that sends email and updates a column (process_flag) to E after the email has been sent.

 

proc sql noprint;
Connect to Greenplm as dbcon (user=xxxxx pw=xxxxx server=xxxxx port=xxxxx database=xxxxxx);

SELECT * INTO :email_flg
FROM connection to dbcon (
SELECT count(1)::smallint
FROM f2_t1
WHERE rflag = 1 AND (process_flag <> 'E')
);
disconnect from dbcon;
quit;

%let email_body = Hello world;
%let to = aa@ss.com;
%let cc = ab@ss.com
%let subject_text = Test;


%if &email_flg > 0 %then %do;

filename outbox email &to;
data _null_;
file outbox
to=(&to)
cc=(&cc)
subject=&subject_text
;
put &email_body;
run;

%end;

 

proc sql;
Connect to xxxx as dbcon (user=xxx pw=xxx server=xxxx port=xxxx database=xxxxx);
execute ( update f2_t1 set process_flag = 'E' where run_flag = 1) by dbcon ;
disconnect from dbcon;
quit;

 

I am updating the process_flag to E once the email for the process has been sent. I create the email_flg to ensure that email doesn't get sent again.


But if the process fails after the email step and before the update statement, the email gets sent twice (or multiple times if the failure keeps occuring after the email step). Is there a way where it is possible to email and do the update in single transaction so that sending email fails if the update fails and vice versa? Or is there any other way to accomplish this scenario in SAS?

 

Thanks!

1 REPLY 1
Shmuel
Garnet | Level 18

I cannot test it, but mainly I believe it is posiible.

I sugget to try it on a sample in work library;

 

FILENAME OUTBOX ...;

data <dsname>;

  modify <dsname>;

     if flag = 0 then do;

        flag = 1;

        file outbox ...;

              to = ...;

              cc = ....;

              subject = ....;

              put ....;

    

     end;

     if _iorc_ = 0 then replace;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 1024 views
  • 0 likes
  • 2 in conversation