<?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 use Do Loop to concate email addresses into single value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912902#M359834</link>
    <description>&lt;P&gt;Did we perhaps miss a Retain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data want (compress=yes);
set have;
by org_id;
length email $32767; /* maximum possible length */
retain email;
if first.org_id
then email = email_address;
else email = catx(",",email,email_address);
if last.org_id;
drop email_address;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2024 21:13:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-01-24T21:13:50Z</dc:date>
    <item>
      <title>How to use Do Loop to concate email addresses into single value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912891#M359826</link>
      <description>&lt;P&gt;I have a table (email_list) with two values:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ORG_ID&lt;/LI&gt;&lt;LI&gt;email_address&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This tables has multiple records with the same ORG_ID and unique email addresses.&amp;nbsp; I want to build a table so that I have a single row for each ORG_ID with all of the individual emails concatenated into a single value with the emails separated by a comma so that I can use that field to email the users.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the count of the records:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;select count(*) into :rec_count&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;from work.email_list;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I want to build the list:&lt;/P&gt;&lt;P&gt;%do j=1 to &amp;amp;rec_count;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if first record:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; org = org_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; email = email_address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if org = org_id then email = email || "', '" || email_address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;org = org_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;email = email_address;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 19:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912891#M359826</guid>
      <dc:creator>jlwatts</dc:creator>
      <dc:date>2024-01-24T19:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do Loop to concate email addresses into single value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912892#M359827</link>
      <description>&lt;P&gt;You don't need the record count.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by org_id;
run;

data want (compress=yes);
set have;
by org_id;
length email $32767; /* maximum possible length */
if first.org_id
then email = email_address;
else email = catx(",",email,email_address);
if last.org_id;
drop email_address;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2024 19:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912892#M359827</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-24T19:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do Loop to concate email addresses into single value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912902#M359834</link>
      <description>&lt;P&gt;Did we perhaps miss a Retain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data want (compress=yes);
set have;
by org_id;
length email $32767; /* maximum possible length */
retain email;
if first.org_id
then email = email_address;
else email = catx(",",email,email_address);
if last.org_id;
drop email_address;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 21:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912902#M359834</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-24T21:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do Loop to concate email addresses into single value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912926#M359847</link>
      <description>&lt;P&gt;Put the SET statement inside the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.org_id);
    set have;
    by org_id;
    length email $1000;
    email=catx(',',email,email_address);
  end;
  drop email_address;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS Don't try to use macro code to generate SAS code until you know what SAS code you need to generate.&amp;nbsp; For this problem there is no need to generate any code, so macro code is not needed.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 03:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912926#M359847</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-25T03:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do Loop to concate email addresses into single value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912942#M359856</link>
      <description>&lt;P&gt;Correct. Missed the RETAIN.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 07:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-Loop-to-concate-email-addresses-into-single-value/m-p/912942#M359856</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-25T07:25:47Z</dc:date>
    </item>
  </channel>
</rss>

