<?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: Concatenate if duplicate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495238#M130661</link>
    <description>&lt;P&gt;Not tested, post test data in the form of a datastep in future please:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  length zcode $2000;
  retain zcode;
  by id;
  if first.id then zcode=zipcode;
  else if index(zcode,zipcode)=0 then zcode=catx(',',zcode,zipcode);
run;&lt;/PRE&gt;
&lt;P&gt;So just check the that zipcode isn't already in the list before catx'ing.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 11:50:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-09-13T11:50:32Z</dc:date>
    <item>
      <title>Concatenate if duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495223#M130658</link>
      <description>I have a dataset that has ID and the zip code. There are some duplicate IDs with different zipcodes. I need to remove the duplicate ids by concatenating the multiple zipcodes separated by a comma.&lt;BR /&gt;The dataset looks like this.&lt;BR /&gt;&lt;BR /&gt;ID zipcode&lt;BR /&gt;001 02115&lt;BR /&gt;001 19103&lt;BR /&gt;002 10001&lt;BR /&gt;003 33130&lt;BR /&gt;003 30303&lt;BR /&gt;003 20008&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The final dataset should look like this.&lt;BR /&gt;&lt;BR /&gt;ID zipcode&lt;BR /&gt;001 02115, 19103&lt;BR /&gt;002 10001&lt;BR /&gt;003 33130, 30303, 20008&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how this can be achieved?&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Thu, 13 Sep 2018 11:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495223#M130658</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-09-13T11:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate if duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495237#M130660</link>
      <description>&lt;P&gt;That's actually a question that has been asked a few times before.&amp;nbsp; Here's one example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/concatenate-last-observation-variable-value/m-p/420054/highlight/true#M103336" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/concatenate-last-observation-variable-value/m-p/420054/highlight/true#M103336&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to add a LENGTH statement for your new variable (the concatenated zip codes) so it has room to store multiple values.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 11:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495237#M130660</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-13T11:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate if duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495238#M130661</link>
      <description>&lt;P&gt;Not tested, post test data in the form of a datastep in future please:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  length zcode $2000;
  retain zcode;
  by id;
  if first.id then zcode=zipcode;
  else if index(zcode,zipcode)=0 then zcode=catx(',',zcode,zipcode);
run;&lt;/PRE&gt;
&lt;P&gt;So just check the that zipcode isn't already in the list before catx'ing.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 11:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495238#M130661</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-13T11:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate if duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495255#M130666</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID:$3. zipcode:$8.;
datalines;
001 02115
001 19103
002 10001
003 33130
003 30303
003 20008
;
run;

proc sort data=have nodupkey;
by id zipcode;
run;

data want(drop=zipcode);
format zipcode_all $50.;
do until (last.id);
set have;
by id;
zipcode_all=catx(',',zipcode_all,zipcode);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 12:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495255#M130666</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-13T12:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate if duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495322#M130704</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a dataset that has ID and the zip code. There are some duplicate IDs with different zipcodes. I need to remove the duplicate ids by concatenating the multiple zipcodes separated by a comma.&lt;BR /&gt;The dataset looks like this.&lt;BR /&gt;&lt;BR /&gt;ID zipcode&lt;BR /&gt;001 02115&lt;BR /&gt;001 19103&lt;BR /&gt;002 10001&lt;BR /&gt;003 33130&lt;BR /&gt;003 30303&lt;BR /&gt;003 20008&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The final dataset should look like this.&lt;BR /&gt;&lt;BR /&gt;ID zipcode&lt;BR /&gt;001 02115, 19103&lt;BR /&gt;002 10001&lt;BR /&gt;003 33130, 30303, 20008&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how this can be achieved?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Every time I see one of these requirements I ask how the concatenated variable is to be used. I seldom get a good response.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-if-duplicate/m-p/495322#M130704</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-13T14:46:09Z</dc:date>
    </item>
  </channel>
</rss>

