<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to automatically send an email given conditions from other tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-automatically-send-an-email-given-conditions-from-other/m-p/923579#M363597</link>
    <description>&lt;P&gt;Good day (Morning)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to automatically create and send an email to customers based on the following scenario. A table is first created from data set using the following code&lt;/P&gt;
&lt;P&gt;proc sql ;&lt;BR /&gt;create table Variable_Count as &lt;BR /&gt;select libname, memname, nobs as totalrows, nvar as totalcolumns from sashelp.vtable&lt;BR /&gt;where libname="WORK" and memname = "RAW_DATA_SET";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;This is done since the variables "totalrows" and "totalclumns" are not constant. Once the table is created, then&amp;nbsp; another table is used which has a non constant number of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code is then used to try and send an email with a created report:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;proc sql ;&lt;/DIV&gt;
&lt;DIV&gt;select count(SAMPLING_POINT)&lt;/DIV&gt;
&lt;DIV&gt;into: Risk_Count from Tested_Count ;&lt;/DIV&gt;
&lt;DIV&gt;Proc sql;&lt;/DIV&gt;
&lt;DIV&gt;select totalcolumns into: Columns from Variable_Count;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; select distinct REQUESTER_EMAIL into: emaillist separated by ',' from RawData_Frame2;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;Data _null_;&lt;/DIV&gt;
&lt;DIV&gt;options emailsys = SMTP;&lt;/DIV&gt;
&lt;DIV&gt;options emailhost = server_rv.randwater.co.za;&lt;/DIV&gt;
&lt;DIV&gt;options emailauthprotocol = NONE;&lt;/DIV&gt;
&lt;DIV&gt;filename Outbox email ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; file Outbox&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %IF &amp;amp;risk_count &amp;gt; 0 and &amp;amp;Columns &amp;gt; 4&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %then %do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp;%let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,)); &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; to = ("&amp;amp;email.")&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; from = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; bc = " "&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; attach = &amp;lt;attachment&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; importance = "HIGH"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sensitivity = "CONFIDENTIAL"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; subject = "Water Quality Risk report"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Good day ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Kindly find the attached risk report';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Warmest regards';%end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%else %do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %IF &amp;amp;risk_count = 0 or &amp;amp;Columns &amp;lt;= 4&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %then %do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; to = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; from = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; bc = " "&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; importance = "HIGH"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sensitivity = "CONFIDENTIAL"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; subject = "Water Quality Risk report"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Good day ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'The report was not generated';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Warmest regards';%end;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;%mend&amp;nbsp; EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;%EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;The following is the log window from the submitted code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS System&lt;/P&gt;
&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Program 5';&lt;BR /&gt;4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';&lt;BR /&gt;5 %LET _CLIENTPROJECTPATH='C:\Users\mmohotsi\OneDrive - Rand Water\Documents\WQS Section\P O&lt;BR /&gt;5 ! C\ZB_POC_ENHANCMENTS\ZB_POC_ENHANCEMENTS.egp';&lt;BR /&gt;6 %LET _CLIENTPROJECTPATHHOST='MMOHOTSI-X7997';&lt;BR /&gt;7 %LET _CLIENTPROJECTNAME='ZB_POC_ENHANCEMENTS.egp';&lt;BR /&gt;8 %LET _SASPROGRAMFILE='';&lt;BR /&gt;9 %LET _SASPROGRAMFILEHOST='';&lt;BR /&gt;10 &lt;BR /&gt;11 ODS _ALL_ CLOSE;&lt;BR /&gt;12 OPTIONS DEV=SVG;&lt;BR /&gt;13 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;14 %macro HTML5AccessibleGraphSupported;&lt;BR /&gt;15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;&lt;BR /&gt;16 %mend;&lt;BR /&gt;17 ODS LISTING GPATH=&amp;amp;sasworklocation;&lt;BR /&gt;18 FILENAME EGHTML TEMP;&lt;BR /&gt;19 ODS HTML5(ID=EGHTML) FILE=EGHTML&lt;BR /&gt;20 OPTIONS(BITMAP_MODE='INLINE')&lt;BR /&gt;21 %HTML5AccessibleGraphSupported&lt;BR /&gt;22 ENCODING='utf-8'&lt;BR /&gt;23 STYLE=HTMLBlue&lt;BR /&gt;24 NOGTITLE&lt;BR /&gt;25 NOGFOOTNOTE&lt;BR /&gt;26 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;27 ;&lt;BR /&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;28 FILENAME EGPDF TEMP;&lt;BR /&gt;29 ODS PDF(ID=EGPDF) FILE=EGPDF STYLE=Pearl;&lt;BR /&gt;NOTE: Writing ODS PDF(EGPDF) output to DISK destination "EGPDF", printer "PDF".&lt;BR /&gt;30 FILENAME EGSR TEMP;&lt;BR /&gt;31 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR&lt;BR /&gt;32 STYLE=HTMLBlue&lt;BR /&gt;33 NOGTITLE&lt;BR /&gt;34 NOGFOOTNOTE&lt;BR /&gt;35 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;36 ENCODING=UTF8&lt;BR /&gt;37 options(rolap="on")&lt;BR /&gt;38 ;&lt;BR /&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;39 &lt;BR /&gt;40 &lt;BR /&gt;41 %macro EmailRisk;&lt;BR /&gt;42 proc sql ;&lt;BR /&gt;43 select count(SAMPLING_POINT)&lt;BR /&gt;44 into: Risk_Count from Tested_Count ;&lt;BR /&gt;45 Proc sql;&lt;BR /&gt;46 select totalcolumns into: Columns from Variable_Count;&lt;BR /&gt;47 quit;&lt;BR /&gt;48 &lt;BR /&gt;49 proc sql ;&lt;BR /&gt;50 select distinct REQUESTER_EMAIL into: emaillist separated by ',' from RawData_Frame2;&lt;BR /&gt;51 quit;&lt;BR /&gt;52 Data _null_;&lt;BR /&gt;53 options emailsys = SMTP;&lt;BR /&gt;54 options emailhost = rvexchsrv02.randwater.co.za;&lt;BR /&gt;The SAS System&lt;/P&gt;
&lt;P&gt;55 options emailauthprotocol = NONE;&lt;BR /&gt;56 filename Outbox email ;&lt;BR /&gt;57 file Outbox&lt;BR /&gt;58 %IF &amp;amp;risk_count &amp;gt; 0 and &amp;amp;Columns &amp;gt; 4&lt;BR /&gt;59 %then %do;&lt;BR /&gt;60 %do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));&lt;BR /&gt;61 %end;&lt;BR /&gt;62 %let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,)); &lt;BR /&gt;63 to = ("&amp;amp;email.")&lt;BR /&gt;64 from = "mmohotsi@randwater.co.za"&lt;BR /&gt;65 bc = " "&lt;BR /&gt;66 attach = &amp;lt;attachment&amp;gt;&lt;BR /&gt;67 importance = "HIGH"&lt;BR /&gt;68 sensitivity = "CONFIDENTIAL"&lt;BR /&gt;69 subject = "Water Quality Risk report"&lt;BR /&gt;70 &lt;BR /&gt;71 %put 'Good day ';&lt;BR /&gt;72 %put ' ';&lt;BR /&gt;73 %put 'Kindly find the attached risk report';&lt;BR /&gt;74 %put ' ';&lt;BR /&gt;75 %put 'Warmest regards';%end;&lt;BR /&gt;76 &lt;BR /&gt;77 %else %do; &lt;BR /&gt;78 &lt;BR /&gt;79 %IF &amp;amp;risk_count = 0 or &amp;amp;Columns &amp;lt;= 4&lt;BR /&gt;80 %then %do;&lt;BR /&gt;81 to = "mmohotsi@randwater.co.za"&lt;BR /&gt;82 from = "mmohotsi@randwater.co.za"&lt;BR /&gt;83 bc = " "&lt;BR /&gt;84 importance = "HIGH"&lt;BR /&gt;85 sensitivity = "CONFIDENTIAL"&lt;BR /&gt;86 subject = "Water Quality Risk report"&lt;BR /&gt;87 &lt;BR /&gt;88 %put 'Good day ';&lt;BR /&gt;89 %put ' ';&lt;BR /&gt;90 %put 'The report was not generated';&lt;BR /&gt;91 %put ' ';&lt;BR /&gt;92 %put 'Warmest regards';%end;&lt;BR /&gt;93 %end;&lt;BR /&gt;94 %mend EmailRisk;&lt;BR /&gt;95 %EmailRisk;&lt;BR /&gt;NOTE: The PROCEDURE SQL printed page 1.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.33 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;NOTE: The PROCEDURE SQL printed page 2.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.10 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;NOTE: The PROCEDURE SQL printed page 3.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.10 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;The SAS System&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;'Good day '&lt;BR /&gt;' '&lt;BR /&gt;'The report was not generated'&lt;BR /&gt;' '&lt;BR /&gt;'Warmest regards'&lt;BR /&gt;96 &lt;BR /&gt;97 &lt;BR /&gt;98 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;99 %LET _CLIENTPROCESSFLOWNAME=;&lt;BR /&gt;100 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;101 %LET _CLIENTPROJECTPATHHOST=;&lt;BR /&gt;102 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;103 %LET _SASPROGRAMFILE=;&lt;BR /&gt;104 %LET _SASPROGRAMFILEHOST=;&lt;BR /&gt;105 &lt;BR /&gt;106 ;*';*";*/;quit;run;&lt;BR /&gt;____&lt;BR /&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;107 ODS _ALL_ CLOSE;&lt;BR /&gt;NOTE: ODS PDF(EGPDF) printed 3 pages to &lt;BR /&gt;C:\Users\mmohotsi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-21416-0cad17d0\contents\SAS Temporary &lt;BR /&gt;Files\_TD18000_MMOHOTSI-X7997_\#LN00777.&lt;BR /&gt;108 &lt;BR /&gt;109 &lt;BR /&gt;110 QUIT; RUN;&lt;BR /&gt;111&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2024 11:43:30 GMT</pubDate>
    <dc:creator>mmohotsi</dc:creator>
    <dc:date>2024-04-09T11:43:30Z</dc:date>
    <item>
      <title>How to automatically send an email given conditions from other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automatically-send-an-email-given-conditions-from-other/m-p/923579#M363597</link>
      <description>&lt;P&gt;Good day (Morning)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to automatically create and send an email to customers based on the following scenario. A table is first created from data set using the following code&lt;/P&gt;
&lt;P&gt;proc sql ;&lt;BR /&gt;create table Variable_Count as &lt;BR /&gt;select libname, memname, nobs as totalrows, nvar as totalcolumns from sashelp.vtable&lt;BR /&gt;where libname="WORK" and memname = "RAW_DATA_SET";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;This is done since the variables "totalrows" and "totalclumns" are not constant. Once the table is created, then&amp;nbsp; another table is used which has a non constant number of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code is then used to try and send an email with a created report:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;proc sql ;&lt;/DIV&gt;
&lt;DIV&gt;select count(SAMPLING_POINT)&lt;/DIV&gt;
&lt;DIV&gt;into: Risk_Count from Tested_Count ;&lt;/DIV&gt;
&lt;DIV&gt;Proc sql;&lt;/DIV&gt;
&lt;DIV&gt;select totalcolumns into: Columns from Variable_Count;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; select distinct REQUESTER_EMAIL into: emaillist separated by ',' from RawData_Frame2;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;Data _null_;&lt;/DIV&gt;
&lt;DIV&gt;options emailsys = SMTP;&lt;/DIV&gt;
&lt;DIV&gt;options emailhost = server_rv.randwater.co.za;&lt;/DIV&gt;
&lt;DIV&gt;options emailauthprotocol = NONE;&lt;/DIV&gt;
&lt;DIV&gt;filename Outbox email ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; file Outbox&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %IF &amp;amp;risk_count &amp;gt; 0 and &amp;amp;Columns &amp;gt; 4&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %then %do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp;%let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,)); &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; to = ("&amp;amp;email.")&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; from = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; bc = " "&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; attach = &amp;lt;attachment&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; importance = "HIGH"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sensitivity = "CONFIDENTIAL"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; subject = "Water Quality Risk report"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Good day ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Kindly find the attached risk report';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Warmest regards';%end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%else %do;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %IF &amp;amp;risk_count = 0 or &amp;amp;Columns &amp;lt;= 4&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %then %do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; to = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; from = "mmohotsi@randwater.co.za"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; bc = " "&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; importance = "HIGH"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sensitivity = "CONFIDENTIAL"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; subject = "Water Quality Risk report"&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Good day ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'The report was not generated';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put ' ';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; %put 'Warmest regards';%end;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;%end;&lt;/DIV&gt;
&lt;DIV&gt;%mend&amp;nbsp; EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;%EmailRisk;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;The following is the log window from the submitted code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS System&lt;/P&gt;
&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Program 5';&lt;BR /&gt;4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';&lt;BR /&gt;5 %LET _CLIENTPROJECTPATH='C:\Users\mmohotsi\OneDrive - Rand Water\Documents\WQS Section\P O&lt;BR /&gt;5 ! C\ZB_POC_ENHANCMENTS\ZB_POC_ENHANCEMENTS.egp';&lt;BR /&gt;6 %LET _CLIENTPROJECTPATHHOST='MMOHOTSI-X7997';&lt;BR /&gt;7 %LET _CLIENTPROJECTNAME='ZB_POC_ENHANCEMENTS.egp';&lt;BR /&gt;8 %LET _SASPROGRAMFILE='';&lt;BR /&gt;9 %LET _SASPROGRAMFILEHOST='';&lt;BR /&gt;10 &lt;BR /&gt;11 ODS _ALL_ CLOSE;&lt;BR /&gt;12 OPTIONS DEV=SVG;&lt;BR /&gt;13 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;14 %macro HTML5AccessibleGraphSupported;&lt;BR /&gt;15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;&lt;BR /&gt;16 %mend;&lt;BR /&gt;17 ODS LISTING GPATH=&amp;amp;sasworklocation;&lt;BR /&gt;18 FILENAME EGHTML TEMP;&lt;BR /&gt;19 ODS HTML5(ID=EGHTML) FILE=EGHTML&lt;BR /&gt;20 OPTIONS(BITMAP_MODE='INLINE')&lt;BR /&gt;21 %HTML5AccessibleGraphSupported&lt;BR /&gt;22 ENCODING='utf-8'&lt;BR /&gt;23 STYLE=HTMLBlue&lt;BR /&gt;24 NOGTITLE&lt;BR /&gt;25 NOGFOOTNOTE&lt;BR /&gt;26 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;27 ;&lt;BR /&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;28 FILENAME EGPDF TEMP;&lt;BR /&gt;29 ODS PDF(ID=EGPDF) FILE=EGPDF STYLE=Pearl;&lt;BR /&gt;NOTE: Writing ODS PDF(EGPDF) output to DISK destination "EGPDF", printer "PDF".&lt;BR /&gt;30 FILENAME EGSR TEMP;&lt;BR /&gt;31 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR&lt;BR /&gt;32 STYLE=HTMLBlue&lt;BR /&gt;33 NOGTITLE&lt;BR /&gt;34 NOGFOOTNOTE&lt;BR /&gt;35 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;36 ENCODING=UTF8&lt;BR /&gt;37 options(rolap="on")&lt;BR /&gt;38 ;&lt;BR /&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;39 &lt;BR /&gt;40 &lt;BR /&gt;41 %macro EmailRisk;&lt;BR /&gt;42 proc sql ;&lt;BR /&gt;43 select count(SAMPLING_POINT)&lt;BR /&gt;44 into: Risk_Count from Tested_Count ;&lt;BR /&gt;45 Proc sql;&lt;BR /&gt;46 select totalcolumns into: Columns from Variable_Count;&lt;BR /&gt;47 quit;&lt;BR /&gt;48 &lt;BR /&gt;49 proc sql ;&lt;BR /&gt;50 select distinct REQUESTER_EMAIL into: emaillist separated by ',' from RawData_Frame2;&lt;BR /&gt;51 quit;&lt;BR /&gt;52 Data _null_;&lt;BR /&gt;53 options emailsys = SMTP;&lt;BR /&gt;54 options emailhost = rvexchsrv02.randwater.co.za;&lt;BR /&gt;The SAS System&lt;/P&gt;
&lt;P&gt;55 options emailauthprotocol = NONE;&lt;BR /&gt;56 filename Outbox email ;&lt;BR /&gt;57 file Outbox&lt;BR /&gt;58 %IF &amp;amp;risk_count &amp;gt; 0 and &amp;amp;Columns &amp;gt; 4&lt;BR /&gt;59 %then %do;&lt;BR /&gt;60 %do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));&lt;BR /&gt;61 %end;&lt;BR /&gt;62 %let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,)); &lt;BR /&gt;63 to = ("&amp;amp;email.")&lt;BR /&gt;64 from = "mmohotsi@randwater.co.za"&lt;BR /&gt;65 bc = " "&lt;BR /&gt;66 attach = &amp;lt;attachment&amp;gt;&lt;BR /&gt;67 importance = "HIGH"&lt;BR /&gt;68 sensitivity = "CONFIDENTIAL"&lt;BR /&gt;69 subject = "Water Quality Risk report"&lt;BR /&gt;70 &lt;BR /&gt;71 %put 'Good day ';&lt;BR /&gt;72 %put ' ';&lt;BR /&gt;73 %put 'Kindly find the attached risk report';&lt;BR /&gt;74 %put ' ';&lt;BR /&gt;75 %put 'Warmest regards';%end;&lt;BR /&gt;76 &lt;BR /&gt;77 %else %do; &lt;BR /&gt;78 &lt;BR /&gt;79 %IF &amp;amp;risk_count = 0 or &amp;amp;Columns &amp;lt;= 4&lt;BR /&gt;80 %then %do;&lt;BR /&gt;81 to = "mmohotsi@randwater.co.za"&lt;BR /&gt;82 from = "mmohotsi@randwater.co.za"&lt;BR /&gt;83 bc = " "&lt;BR /&gt;84 importance = "HIGH"&lt;BR /&gt;85 sensitivity = "CONFIDENTIAL"&lt;BR /&gt;86 subject = "Water Quality Risk report"&lt;BR /&gt;87 &lt;BR /&gt;88 %put 'Good day ';&lt;BR /&gt;89 %put ' ';&lt;BR /&gt;90 %put 'The report was not generated';&lt;BR /&gt;91 %put ' ';&lt;BR /&gt;92 %put 'Warmest regards';%end;&lt;BR /&gt;93 %end;&lt;BR /&gt;94 %mend EmailRisk;&lt;BR /&gt;95 %EmailRisk;&lt;BR /&gt;NOTE: The PROCEDURE SQL printed page 1.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.33 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;NOTE: The PROCEDURE SQL printed page 2.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.10 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;NOTE: The PROCEDURE SQL printed page 3.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.10 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;The SAS System&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;'Good day '&lt;BR /&gt;' '&lt;BR /&gt;'The report was not generated'&lt;BR /&gt;' '&lt;BR /&gt;'Warmest regards'&lt;BR /&gt;96 &lt;BR /&gt;97 &lt;BR /&gt;98 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;99 %LET _CLIENTPROCESSFLOWNAME=;&lt;BR /&gt;100 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;101 %LET _CLIENTPROJECTPATHHOST=;&lt;BR /&gt;102 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;103 %LET _SASPROGRAMFILE=;&lt;BR /&gt;104 %LET _SASPROGRAMFILEHOST=;&lt;BR /&gt;105 &lt;BR /&gt;106 ;*';*";*/;quit;run;&lt;BR /&gt;____&lt;BR /&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;107 ODS _ALL_ CLOSE;&lt;BR /&gt;NOTE: ODS PDF(EGPDF) printed 3 pages to &lt;BR /&gt;C:\Users\mmohotsi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-21416-0cad17d0\contents\SAS Temporary &lt;BR /&gt;Files\_TD18000_MMOHOTSI-X7997_\#LN00777.&lt;BR /&gt;108 &lt;BR /&gt;109 &lt;BR /&gt;110 QUIT; RUN;&lt;BR /&gt;111&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 11:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automatically-send-an-email-given-conditions-from-other/m-p/923579#M363597</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2024-04-09T11:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to automatically send an email given conditions from other tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automatically-send-an-email-given-conditions-from-other/m-p/923581#M363599</link>
      <description>&lt;P&gt;It looks you are mixing up 4GL and macro language, try this one;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro EmailRisk;
proc sql ;
select count(SAMPLING_POINT)
into: Risk_Count from Tested_Count ;
Proc sql;
select totalcolumns into: Columns from Variable_Count;
quit;
 
proc sql ;
select distinct REQUESTER_EMAIL into: emaillist separated by ',' from RawData_Frame2;
quit;
options emailsys = SMTP;
options emailhost = server_rv.randwater.co.za;
options emailauthprotocol = NONE;

%IF &amp;amp;risk_count &amp;gt; 0 and &amp;amp;Columns &amp;gt; 4  
%then %do;
%do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));
filename Outbox email
%let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,));
to = ("&amp;amp;email.")
from = "mmohotsi@randwater.co.za"
bc = " "
/*attach = &amp;lt;attachment&amp;gt;*/
importance = "HIGH"
sensitivity = "CONFIDENTIAL"
subject = "Water Quality Risk report"
;
Data _null_;
file Outbox; 
put 'Good day ';
put ' ';
put 'Kindly find the attached risk report';
put ' ';
put 'Warmest regards';
run;
filename Outbox;
%end;
%end;
 
%else %do;
 
%IF &amp;amp;risk_count = 0 or &amp;amp;Columns &amp;lt;= 4  
%then %do;
filename Outbox email
to = "mmohotsi@randwater.co.za"
from = "mmohotsi@randwater.co.za"
bc = " "
importance = "HIGH"
sensitivity = "CONFIDENTIAL"
subject = "Water Quality Risk report"
;
data _null_;
file Outbox; 
put 'Good day ';
put ' ';
put 'The report was not generated';
put ' ';
put 'Warmest regards';
run;
filename Outbox;

%end; 
%end;
%mend  EmailRisk;
%EmailRisk;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 12:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automatically-send-an-email-given-conditions-from-other/m-p/923581#M363599</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-09T12:00:48Z</dc:date>
    </item>
  </channel>
</rss>

