<?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 Re: Fetching an email address from an external table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/664010#M198326</link>
    <description>&lt;P&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jun 2020 15:50:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-06-22T15:50:25Z</dc:date>
    <item>
      <title>Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/663977#M198314</link>
      <description>&lt;P&gt;Users log calls using SQL database and the sample table is as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Customers;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input customer : $20. start_date : $7. end_date : $7. sampling_point: $35. name1 : $14. Action : $15. Customer_email : $30.;&lt;BR /&gt;datalines;&lt;BR /&gt;Tshepo 17feb19 21mar20 "d-pelin","d-roode","m-vaalkop" "tc","Mn" complete mmohotsi@gmail.com&lt;BR /&gt;Mighty 21Apr20 30Apr20 "d-air_res","d-deel" "hpc","Turb" incomplete mighty@gmail.co.com&lt;BR /&gt;Tumisi 17Apr19 26Apr20 "d-air_res","d-sasol" "Mn","Colour" incomplete Tumisi@gmail.com&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set Customers;&lt;BR /&gt;where action = 'incomplete';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was also able to extract the requested data from the database using the code below:&lt;/P&gt;&lt;P&gt;filename torun temp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;file torun;&lt;BR /&gt;set want;&lt;BR /&gt;put "****** QUERY FOR CUSTOMER : " customer " ******;";&lt;/P&gt;&lt;P&gt;put "proc sql; " / "create table " customer " as" / " select sample.sample_number,sample.sampling_point,sample.sampled_date,result.name,&lt;BR /&gt;result.numeric_entry,result.status, result.reportable";&lt;BR /&gt;put " from vgsql1.sample, vgsql1.result" / " where sample.sample_number=result.sample_number and" / " sample.sampled_date between ";&lt;BR /&gt;put "'" start_date +(-1) "'d and" ;&lt;BR /&gt;put "'" end_date "'d" ;&lt;BR /&gt;put "and sample.sampling_point in (" sampling_point") and " /&lt;BR /&gt;" result.name in (" name1") and " ;&lt;BR /&gt;put"result.status = 'A';" / " quit;";&lt;BR /&gt;run;&lt;BR /&gt;%include torun;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A macro was then used to generate a report based on the information on the data using the code below:&lt;/P&gt;&lt;P&gt;The two reports named Mighty and Tumisi are attached&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro poc_;&lt;BR /&gt;ODS _ALL_ CLOSE;&lt;BR /&gt;ods pdf file="&amp;amp;_POC_\Customer_Report&amp;amp;Today&amp;amp;_pdf_";&lt;BR /&gt;ODS ESCAPECHAR = '~';&lt;BR /&gt;proc sql NOPRINT;&lt;BR /&gt;select count(name) into: emailed&lt;BR /&gt;from MIGHTY;&lt;BR /&gt;quit;&lt;BR /&gt;%If &amp;amp;emailed &amp;gt;=0 %then %do;&lt;BR /&gt;Data tosend;&lt;BR /&gt;text = "There are no results for the information provided from date_started to date_ended";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Proc report data = tosend;&lt;BR /&gt;COLUMN text;&lt;BR /&gt;define text / '';&lt;BR /&gt;title1 j=c Color = biv bold italic height=4.5&lt;BR /&gt;"~{style[preimage='\\him\DataStore\Internal\HIM_Water_Quality_Administration\SASImplementation\RW_Logo\LogoRW_29May2016.bmp'] } " ;&lt;BR /&gt;title2 j=c "~{style[vjust=m]Customer report}";&lt;BR /&gt;title4 j=C Color = biv "Report generated on: %sysfunc(today(), weekdate.) at %sysfunc(time(), timeAMPM8.)";&lt;BR /&gt;footnote1 'Information management Report Compiled by Water Quality Statistician Scientific Services' ;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%END;&lt;/P&gt;&lt;P&gt;%ELSE&lt;/P&gt;&lt;P&gt;%DO;&lt;BR /&gt;Proc report data = MIGHTY;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%END;&lt;BR /&gt;ODS _ALL_ CLOSE;&lt;BR /&gt;QUIT;&lt;BR /&gt;%mend poc_;&lt;BR /&gt;%poc_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The report was then send to the customer using the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let _POC_ = C:\Users\mmohotsi\Documents\P_O_C\Reports;&lt;BR /&gt;%let _pdf_ = .pdf;&lt;BR /&gt;%let today = %sysfunc(today(), date9.);&lt;BR /&gt;options emailsys = SMTP;&lt;BR /&gt;options emailhost = email_host;&lt;BR /&gt;options emailauthprotocol = NONE;&lt;/P&gt;&lt;P&gt;filename Outbox email;&lt;BR /&gt;Data _null_;&lt;BR /&gt;file Outbox&lt;BR /&gt;to = ("mmohotsi@randwater.co.za" )&lt;BR /&gt;from = "mmohotsi@randwater.co.za"&lt;BR /&gt;Subject = "POC Prototype report"&lt;BR /&gt;attach ="&amp;amp;_POC_\Customer_Report&amp;amp;Today&amp;amp;_pdf_";&lt;BR /&gt;&lt;BR /&gt;put 'Good day ';&lt;BR /&gt;put ' ';&lt;BR /&gt;put 'Kindly find the attached report for your attention';&lt;BR /&gt;put ' ';&lt;BR /&gt;put 'For any queries kindly contact Mighty Mohotsi on mmohotsi@randwater.co.za';&lt;BR /&gt;put ' ';&lt;BR /&gt;put 'Warmest regards';&lt;BR /&gt;put ' ';&lt;BR /&gt;Put 'Mighty';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find how do I automate this process such that each report is emailed&amp;nbsp; to the intended recipient as provided for in the "Customers" data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 12:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/663977#M198314</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2020-06-22T12:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/664010#M198326</link>
      <description>&lt;P&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 15:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/664010#M198326</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-22T15:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/664075#M198345</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro send_email;
	%let _POC_ = C:\Users\mmohotsi\Documents\P_O_C\Reports;
	%let _pdf_ = .pdf;
	%let today = %sysfunc(today(), date9.);
	options emailsys = SMTP;
	options emailhost = email_host;
	options emailauthprotocol = NONE;

	proc sql;
	select distinct Customer_email into: email_list separated by ',' from Customers
	where action = 'complete';
	quit;

	%do i = 1 %to %sysfunc(countw("&amp;amp;emaillist",','));
	    %let email=%scan(&amp;amp;emaillist,&amp;amp;i.,%str(,));
		filename Outbox email;
		Data _null_;
		file Outbox
		to = ("&amp;amp;email." )
		from = "mmohotsi@randwater.co.za"
		Subject = "POC Prototype report"
		attach ="&amp;amp;_POC_\Customer_Report&amp;amp;Today&amp;amp;_pdf_";

		put 'Good day ';
		put ' ';
		put 'Kindly find the attached report for your attention';
		put ' ';
		put 'For any queries kindly contact Mighty Mohotsi on mmohotsi@randwater.co.za';
		put ' ';
		put 'Warmest regards';
		put ' ';
		Put 'Mighty';
		run;
	%end;
%mend send_email;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jun 2020 21:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/664075#M198345</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-22T21:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/665864#M199151</link>
      <description>&lt;P&gt;The programme works but the challenge is attaching the report that corresponds to the right customer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way of attaching the two reports Mighty.sas7bdat and tumisi.sas7bdat&amp;nbsp;in pdf to their corresponding emails as given in the Customers table?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 17:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/665864#M199151</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2020-06-29T17:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/665911#M199171</link>
      <description>&lt;P&gt;Name the reports in such a way that the report name is unique by customer and out put. Instead of calling it a generic name custom_report&amp;amp;today.&amp;amp;_pdf_. you can call it&amp;nbsp;custom_report&amp;lt;customername&amp;gt;&amp;amp;today.&amp;amp;_pdf_.&amp;nbsp; or&amp;nbsp;custom_report_&amp;lt;mighty/any uniquename&amp;gt;&amp;amp;today.&amp;amp;_pdf_.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 20:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/665911#M199171</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-29T20:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching an email address from an external table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/666028#M199225</link>
      <description>thanks for the response&lt;BR /&gt;When I created a data set as:&lt;BR /&gt;ods pdf file="&amp;amp;_POC_\Customer_Report&amp;amp;Today&amp;amp;_pdf_";&lt;BR /&gt;&lt;BR /&gt;I had challenges creating a unique data for each report for each customer using the customer name as the name of the report&lt;BR /&gt;&lt;BR /&gt;Can SAS generate a unique name for me that corresponds to the Data set for Mighty or Tumisi as you indicated that will be send to the corresponding emails?</description>
      <pubDate>Tue, 30 Jun 2020 10:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-an-email-address-from-an-external-table/m-p/666028#M199225</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2020-06-30T10:51:11Z</dc:date>
    </item>
  </channel>
</rss>

