/******************************************************************************
 * Programme : Notification par e-mail SAS
 * Reference : NOTIFID0A4
 * Source    : https://www.wearecas.eu/en/sampleCode/NOTIFID0A4
 ******************************************************************************/

/* --- BLOC 1 --- */
dm 'output;clear';
dm 'log;clear';

/* --- BLOC 2 --- */
%macro startT;
data _null_;
   tempdate=put(date(),weekdate32.);
   temptime=put(time(),hhmm5.);
   call symput("startdate",tempdate);
   call symput("starttime",temptime);
run;
%mend;

/* --- BLOC 3 --- */
%macro endT;
data _null_;
   tempdate=put(date(),weekdate32.);
   temptime=put(time(),hhmm5.);
   call symput("enddate",tempdate);
   call symput("endtime",temptime);
run;
%mend;

/* --- BLOC 4 --- */
%macro email(dt);
   /* Set up the options for the email. */
   OPTIONS EMAILSYS=smtp EMAILID="kfong @cornerstone.com"
   EMAILHOST=CRDCEXCH10.cornerstone.com;
   FILENAME mymail
   EMAIL
   TO = ("kfong @cornerstone.com")
   SUBJECT="&dt. finished"
   ;
   /* Send the email and define the message to send. */
   DATA _NULL_;
   FILE mymail;
   PUT "Hello,";
   PUT " ";
   PUT "The code for &dt. has finished running.";
   PUT "Start: &StartTime. &StartDate. ";
   PUT "End:   &EndTime. &EndDate. ";
   RUN;
%mend;

/* --- BLOC 5 --- */
%StartT;
%EndT;

/* --- BLOC 6 --- */
data _null_;
   put "Hello world!";
run;

/* --- BLOC 7 --- */
%Email(test);

