<?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: How to send an email from an existing table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795904#M255343</link>
    <description>&lt;P&gt;Blank lines in Datalines are a bad idea. Is that actually the code?&lt;/P&gt;
&lt;P&gt;When I run that I get this in the log:&lt;/P&gt;
&lt;PRE&gt;156  data card;
157
158       infile datalines truncover dlm='|' dsd;
159
160       input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;
161
162       datalines;

NOTE: The data set WORK.CARD has 10 observations and 5 variables.
NOTE: DATA statement used (Total process time):
&lt;/PRE&gt;
&lt;P&gt;Which means there are 5 observations with all missing data and if something is supposed to be done with each observation then you have lots of blank observations to deal with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hi, the input:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data card;

     infile datalines truncover dlm='|' dsd;

     input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;

     datalines;

1|1234567|21312|1231243423|abc@gmail.com

1|1234567|21312|2341245543|abc@gmail.com

12|2342344|23466|8979879879|rer@gmail.com

34|2344523|98986|3453263223|sdr@gmail.com

22|1235534|23214|2353662623|wwt@gmail.com
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 13 Feb 2022 08:18:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-02-13T08:18:37Z</dc:date>
    <item>
      <title>How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795869#M255322</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have the following final table (every day the table contents change):&lt;/P&gt;&lt;P&gt;&lt;U&gt;CARD Table&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shlomiohana_0-1644691710580.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68416i8AB19113B3712C9C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shlomiohana_0-1644691710580.png" alt="shlomiohana_0-1644691710580.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;The code:&lt;/U&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro mymail(
  from=freetalk@gmail.com,
  to=,
  acct_no=,
  branch_id=,
  card=,
  id=
  );

  filename outbox email "freetalk@gmail.com" encoding="utf-8";

  data _null_;
    file outbox
    to=( "&amp;amp;to")
    from= ("&amp;amp;from")
    subject= "Closing &amp;amp;acct_no - &amp;amp;branch_id";
    put "Cancel any instructions in the account &amp;amp;acct_no - &amp;amp;branch_id :" ;
    put /;
    put " &amp;amp;card - &amp;amp;id";
    put /;
      
  run;
%mend;


data _null_;
  set CARD;
  length cmd $500;
  cmd=cats( '%mymail(to=',Mail_to,',acct_no=',Account_Number,',branch_id=',Branch_ID,',card=',Card_No,',id=',ID,')' );
  call execute(cmd);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shlomiohana_2-1644692062039.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68418i158D1C2065774F46/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shlomiohana_2-1644692062039.png" alt="shlomiohana_2-1644692062039.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sorry for the pictures, but the post will be deleted if not&amp;nbsp;&lt;SPAN class=""&gt;automatically.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I would appreciate your help.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Feb 2022 19:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795869#M255322</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2022-02-12T19:18:22Z</dc:date>
    </item>
    <item>
      <title>How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795860#M255385</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have the following final table (every day the table contents change):&lt;/P&gt;&lt;P&gt;&lt;U&gt;CARD Table&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shlomiohana_1-1644688911730.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68414i3F7C1534864A534E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shlomiohana_1-1644688911730.png" alt="shlomiohana_1-1644688911730.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;The code&lt;/U&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro mymail(
  from=freetalk@gmail.com,
  to=,
  acct_no=,
  branch_id=,
  card=,
  id=
  );

  filename outbox email "freetalk@gmail.com" encoding="utf-8";

  data _null_;
    file outbox
    to=( "&amp;amp;to")
    from= ("&amp;amp;from")
    subject= "Closing &amp;amp;acct_no - &amp;amp;branch_id";
    put "Cancel any instructions in the account &amp;amp;acct_no - &amp;amp;branch_id :" ;
    put /;
    put " &amp;amp;card - &amp;amp;id";
    put /;
      
  run;
%mend;


data _null_;
  set CARD;
  length cmd $500;
  cmd=cats( '%mymail(to=',Mail_to,',acct_no=',Account_Number,',branch_id=',Branch_ID,',card=',Card_No,',id=',ID,')' );
  call execute(cmd);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;According to the code, they will send 5 emails, but I would like to change that they will only send 4 emails.&lt;BR /&gt;When the Branch_ID + Account_Number + ID + Mail_to fields are the same in the CARD table, it will send one email instead of two.&lt;/P&gt;&lt;P&gt;&lt;U&gt;The email will look like this&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shlomiohana_2-1644688997888.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68415i2354CCA7FEB710D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shlomiohana_2-1644688997888.png" alt="shlomiohana_2-1644688997888.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The line&amp;nbsp;&lt;STRONG&gt;2341245543 - 21312&lt;/STRONG&gt; was added to the existing email instead of sending 2 emails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate your help.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Feb 2022 18:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795860#M255385</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2022-02-12T18:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795873#M255324</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that you can send code in a code box, so you could have added code to generate the input data (as expected in this forum). And the expected email as text or inside a comment in the code box as well.&amp;nbsp;I know how to code it if you provide the input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Feb 2022 22:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795873#M255324</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-02-12T22:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795899#M255339</link>
      <description>&lt;P&gt;hi, the input:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data card;

     infile datalines truncover dlm='|' dsd;

     input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;

     datalines;

1|1234567|21312|1231243423|abc@gmail.com

1|1234567|21312|2341245543|abc@gmail.com

12|2342344|23466|8979879879|rer@gmail.com

34|2344523|98986|3453263223|sdr@gmail.com

22|1235534|23214|2353662623|wwt@gmail.com
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Feb 2022 07:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795899#M255339</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2022-02-13T07:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795904#M255343</link>
      <description>&lt;P&gt;Blank lines in Datalines are a bad idea. Is that actually the code?&lt;/P&gt;
&lt;P&gt;When I run that I get this in the log:&lt;/P&gt;
&lt;PRE&gt;156  data card;
157
158       infile datalines truncover dlm='|' dsd;
159
160       input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;
161
162       datalines;

NOTE: The data set WORK.CARD has 10 observations and 5 variables.
NOTE: DATA statement used (Total process time):
&lt;/PRE&gt;
&lt;P&gt;Which means there are 5 observations with all missing data and if something is supposed to be done with each observation then you have lots of blank observations to deal with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hi, the input:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data card;

     infile datalines truncover dlm='|' dsd;

     input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;

     datalines;

1|1234567|21312|1231243423|abc@gmail.com

1|1234567|21312|2341245543|abc@gmail.com

12|2342344|23466|8979879879|rer@gmail.com

34|2344523|98986|3453263223|sdr@gmail.com

22|1235534|23214|2353662623|wwt@gmail.com
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Feb 2022 08:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795904#M255343</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-13T08:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795906#M255344</link>
      <description>&lt;P&gt;Hi, this is the correct code: (no spaces)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data card;
     infile datalines truncover dlm='|' dsd;
     input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;
     datalines;
1|1234567|21312|1231243423|abc@gmail.com
1|1234567|21312|2341245543|abc@gmail.com
12|2342344|23466|8979879879|rer@gmail.com
34|2344523|98986|3453263223|sdr@gmail.com
22|1235534|23214|2353662623|wwt@gmail.com
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Feb 2022 08:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795906#M255344</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2022-02-13T08:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795915#M255350</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp; &amp;nbsp;- thanks for the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not necessary to use a macro for this. It can all be done in one data step using first. and last. with by-variables to control the beginning of a new mail and sending it before the next mail starts. Remember to enable the File statement in the code when you try it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote a "real" program also with the usual bells and whistles, it is included as attachment . And I may have sent test mails to your receivers, I am not sure, so I hope they are fictive mail accounts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data card;
     infile datalines truncover dlm='|' dsd;
     input Branch_ID :20. Account_Number :20. ID :20. Card_No :$20. Mail_to :$20.;
     datalines;
1|1234567|21312|1231243423|abc@gmail.com
1|1234567|21312|2341245543|abc@gmail.com
12|2342344|23466|8979879879|rer@gmail.com
34|2344523|98986|3453263223|sdr@gmail.com
22|1235534|23214|2353662623|wwt@gmail.com
;
run;
	
* Sort to make sure first. and last. will work as expected in data step;
proc sort data=&amp;amp;_INPUT;
	by Branch_ID Account_Number ID Mail_to Card_No;
run;

* Send emails;
%let mail_from = freetalk@gmail.com;
filename outbox email encoding="utf-8";
data _null;
	set card (obs=3);
	by Branch_ID Account_Number ID Mail_to;
	*file outbox;

	if first.Mail_to then do;
		account = catx(' ', Account_Number, '- 1');
		put '!em_subject! Closing ' account; 
		put "!em_from! &amp;amp;mail_from";
		put '!em_to! ' mail_to;

		put 'Cancel any instructions in account ' Account_Number / ;
	end;

	put card_no '-' ID;

	if last.Mail_to then do;
		put '!em_send!';       
		put '!em_newmsg!';     
		put '!em_abort!'; 
	end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I hope you can use it, and don't hesitate&amp;nbsp; to ask any further questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Feb 2022 11:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795915#M255350</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-02-13T11:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795916#M255351</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288727"&gt;@shlomiohana&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used a real mail address in my full program to test it, and I forgot to change the address before I attached it.&lt;/P&gt;
&lt;P&gt;Please remove it from any tests you make.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Feb 2022 11:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795916#M255351</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-02-13T11:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795995#M255386</link>
      <description>&lt;P&gt;I have merged your identical posts.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 06:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/795995#M255386</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-14T06:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to send an email from an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/796093#M255420</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt; Thank you very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 14 Feb 2022 17:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-send-an-email-from-an-existing-table/m-p/796093#M255420</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2022-02-14T17:16:02Z</dc:date>
    </item>
  </channel>
</rss>

