<?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: Merge the comments based on ID and date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643469#M192035</link>
    <description>&lt;P&gt;In a data step, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Define a new character variable (e.g. remarks) with sufficient length. At first.date, set it to remark, otherwise do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;remarks = catx(',',remarks,remark);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use a subsetting if at last.date to only keep one observation per id and date.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2020 05:41:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-28T05:41:40Z</dc:date>
    <item>
      <title>Merge the comments based on ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643467#M192034</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to merge the comments to one row for the duplicate IDs, I ll give you the sample set with expected output.&lt;/P&gt;&lt;PRE&gt;data aaa;
Input ID Date mmddyy10. Remarks$;
format Date mmddyy10.;
cards;
123 05/05/2002 comment1
123 05/05/2002 comment2
123 08/07/2003 comment1
145 03/17/2005 comment1
145 03/17/2005 comment2
145 10/12/2006 comment1
;&lt;/PRE&gt;&lt;P&gt;Expected Output&lt;/P&gt;&lt;P&gt;123 05/05/2002 comment1, comment2&lt;/P&gt;&lt;P&gt;123 08/07/2003 comment1&lt;/P&gt;&lt;P&gt;145 03/17/2005 comment1, comment2&lt;/P&gt;&lt;P&gt;145 10/12/2006 comment1&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 05:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643467#M192034</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-04-28T05:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merge the comments based on ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643469#M192035</link>
      <description>&lt;P&gt;In a data step, do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Define a new character variable (e.g. remarks) with sufficient length. At first.date, set it to remark, otherwise do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;remarks = catx(',',remarks,remark);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use a subsetting if at last.date to only keep one observation per id and date.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 05:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643469#M192035</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-28T05:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merge the comments based on ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643470#M192036</link>
      <description>&lt;P&gt;Idea:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;sort "aaa" by Id and Date, then use set+by in a data step&lt;/LI&gt;
&lt;LI&gt;you will have to create a new variable to hold all remarks, calculating the length could be interesting&lt;/LI&gt;
&lt;LI&gt;join the remarks with &lt;EM&gt;catx&lt;/EM&gt; (as shown by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;)&lt;/LI&gt;
&lt;LI&gt;use &lt;EM&gt;last.date&lt;/EM&gt; and &lt;EM&gt;output&lt;/EM&gt; to control which obs is written to the dataset&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 28 Apr 2020 05:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643470#M192036</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-28T05:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merge the comments based on ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643476#M192041</link>
      <description>&lt;P&gt;please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
Input ID Date mmddyy10. Remarks$;
format Date mmddyy10.;
cards;
123 05/05/2002 comment1
123 05/05/2002 comment2
123 08/07/2003 comment1
145 03/17/2005 comment1
145 03/17/2005 comment2
145 10/12/2006 comment1
;

data want;
length newvar $200.;
set aaa;
by id date notsorted;
retain newvar;
if first.date then newvar=remarks;
else newvar=catx(',',newvar,remarks);
if last.date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Apr 2020 07:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-the-comments-based-on-ID-and-date/m-p/643476#M192041</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-28T07:07:23Z</dc:date>
    </item>
  </channel>
</rss>

