<?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 remove duplicates from a string and a comma at the end in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891849#M352293</link>
    <description>&lt;P&gt;Here is the full program if anyone needs it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want (drop=word i);&lt;BR /&gt;set have;&lt;BR /&gt;length newlist $300 word $100 ;&lt;BR /&gt;do i=1 to countw(have_,',');&lt;BR /&gt;word=scan(have_,i,',');&lt;BR /&gt;if not findw(newlist,have_,',','t') then newlist=catx(',',newlist,word);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt;set want;&lt;BR /&gt;newstring=scan(newlist, 1, ',');&lt;BR /&gt;do i=2 to countw(newlist,',');&lt;BR /&gt;word=scan(newlist, i, ',');&lt;BR /&gt;found=find(newstring, word, 'it');&lt;BR /&gt;if found=0 then newstring=catx(', ', newstring, word);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2023 04:02:02 GMT</pubDate>
    <dc:creator>arde</dc:creator>
    <dc:date>2023-08-31T04:02:02Z</dc:date>
    <item>
      <title>How to remove duplicates from a string and a comma at the end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891842#M352289</link>
      <description>&lt;P&gt;I have data in a variable that contains duplicates and sometimes begins or ends in a comma.&amp;nbsp; I would like to clean it up.&amp;nbsp; Any help is truly appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;TABLE width="338px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="337px"&gt;dog,dog,cat in the hat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="337px"&gt;cat in the hat,dog,mouse,mouse,&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="337px"&gt;,cat in the hat,cat in the hat,cat in the hat&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;TABLE width="225"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="225"&gt;dog,cat in the hat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cat in the hat,dog,mouse&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cat in the hat&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for your assistance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 02:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891842#M352289</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-31T02:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove duplicates from a string and a comma at the end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891847#M352291</link>
      <description>&lt;P&gt;SCAN() the list and use CATX() to build a NEW list.&lt;/P&gt;
&lt;P&gt;So if your dataset is named HAVE the variable is named LIST you can use a step like this to make a new dataset named HAVE with a new variable named NEWLIST.&amp;nbsp; Only add the "word" from the old list that have not already been added to the new list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length newlist $300 word $100 ;
  do i=1 to countw(list,',');
    word=scan(list,i,',');
    if not findw(newlist,list,',','t') then newlist=catx(',',newlist,word);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2023 03:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891847#M352291</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-31T03:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove duplicates from a string and a comma at the end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891848#M352292</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; but that only deletes the commas in the beginning and at the end.&amp;nbsp; I figured out the deleting duplicates (Here it is in case anyone else needs it):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt;set want;&lt;BR /&gt;newstring=scan(newlist, 1, ',');&lt;BR /&gt;do i=2 to countw(newlist,',');&lt;BR /&gt;word=scan(newlist, i, ',');&lt;BR /&gt;found=find(newstring, word, 'it');&lt;BR /&gt;if found=0 then newstring=catx(', ', newstring, word);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 03:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891848#M352292</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-31T03:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove duplicates from a string and a comma at the end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891849#M352293</link>
      <description>&lt;P&gt;Here is the full program if anyone needs it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want (drop=word i);&lt;BR /&gt;set have;&lt;BR /&gt;length newlist $300 word $100 ;&lt;BR /&gt;do i=1 to countw(have_,',');&lt;BR /&gt;word=scan(have_,i,',');&lt;BR /&gt;if not findw(newlist,have_,',','t') then newlist=catx(',',newlist,word);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt;set want;&lt;BR /&gt;newstring=scan(newlist, 1, ',');&lt;BR /&gt;do i=2 to countw(newlist,',');&lt;BR /&gt;word=scan(newlist, i, ',');&lt;BR /&gt;found=find(newstring, word, 'it');&lt;BR /&gt;if found=0 then newstring=catx(', ', newstring, word);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 04:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-duplicates-from-a-string-and-a-comma-at-the-end/m-p/891849#M352293</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-31T04:02:02Z</dc:date>
    </item>
  </channel>
</rss>

