Posted By

ccw on 03/29/12


Tagged

notification etl sas


Versions (?)

[SAS] ETL Email Noticiation


 / Published in: SAS
 

An example to notify users with ETL job status

  1. %let INFO_ADDR_1=[email protected];
  2. %let INFO_ADDR_LENGTH=1;
  3.  
  4. %let DEBUG_ADDR_1=[email protected];
  5. %let DEBUG_ADDR_LENGTH=1;
  6.  
  7. %let DB_ADDR_1=[email protected];
  8. %let DB_ADDR_LENGTH=1;
  9.  
  10. %let DEBUG_FLAG=N;
  11.  
  12. options mprint;
  13.  
  14. %macro etls_sendEmail(address=, subject=, message=);
  15.  
  16. filename sendMail email "&address" subject="SAS ETL Notice - &subject";
  17.  
  18. %local etls_syntaxcheck;
  19. %let etls_syntaxcheck = %sysfunc(getoption(syntaxcheck));
  20. /* Turn off syntaxcheck option to perform following steps */
  21. options nosyntaxcheck;
  22.  
  23. data _null_;
  24. file sendMail;
  25. dttm = put(datetime(),nldatm.);
  26. put dttm "&message.";
  27. run;
  28.  
  29. /* Reset syntaxcheck option to previous setting */
  30. options &etls_syntaxcheck;
  31. %mend etls_sendEmail;
  32.  
  33. %macro etls_sendAllEmails(type=INFO,subject=, message=);
  34. %DO I = 1 %TO &&&type._ADDR_LENGTH;
  35. %PUT Sending email to &&&type._ADDR_&I;
  36. %etls_sendEmail(address = &&&type._ADDR_&I,
  37. subject = &subject,
  38. message = &message);
  39. %END;
  40. %mend etls_sendAllEmails;
  41.  
  42. %macro etls_jobRCChk(type=DEBUG, subject=Job Status [&etls_jobName]);
  43. %if (&DEBUG_FLAG eq Y) %then %do;
  44. %if (&job_rc eq 0) %then
  45. %do;
  46. %etls_sendAllEmails(type = &type,
  47. subject = &subject,
  48. message = Success);
  49. %end;
  50. %else %if (&job_rc ge 5) %then
  51. %do;
  52. %etls_sendAllEmails(type = &type,
  53. subject = &subject,
  54. message = Fail);
  55. %end;
  56. %end;
  57. %mend etls_jobRCChk;
  58.  
  59. %macro etls_flowNotice(type=S, flow=CMDM);
  60. %if (&type eq E) %then
  61. %do;
  62. %etls_sendAllEmails(subject = Process Status,
  63. message = &flow Batch Job Completed Successfully);
  64. %end;
  65. %else
  66. %do;
  67. %etls_sendAllEmails(subject = Process Status,
  68. message = &flow Batch Job Started);
  69. %end;
  70. %mend etls_flowNotice;
  71.  
  72. %macro etls_dataValidChk(tblSRC=,cntSRC=,tblDist=,cntDist=);
  73. %if (&cntSRC ge 0 and &cntDist ge 0) %then
  74. %do;
  75. %etls_sendAllEmails(type = INFO,
  76. subject = Data Loading Checkpoint,
  77. message = Loading [&cntSRC] records from &tblSRC and output [&cntDist] records into &tblDist);
  78. %end;
  79. %mend etls_dataValidChk;

Report this snippet  

You need to login to post a comment.