<?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: Remove duplicates from a value of the column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850936#M336283</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4;
input column : $ 20.;
datalines4;
1,1                
5,11,12,13,5,11,12 
2,2,2              
1,1,1,1            
;;;;

data want;
 set have;
 array x{999} $ 80;
 do i=1 to countw(column,',');
   temp=scan(column,i,',');
   if temp not in x then x{i}=temp;
 end;
 want=catx(',',of x{*});
 keep column want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 23 Dec 2022 11:56:43 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-12-23T11:56:43Z</dc:date>
    <item>
      <title>Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850778#M336212</link>
      <description>&lt;P&gt;want:&lt;/P&gt;&lt;P&gt;column1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;5,11,12,13&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;actual data for column1:&lt;/P&gt;&lt;P&gt;column1&lt;/P&gt;&lt;P&gt;1,1&lt;/P&gt;&lt;P&gt;5,11,12,13,5,11,12&lt;/P&gt;&lt;P&gt;2,2,2&lt;/P&gt;&lt;P&gt;1,1,1,1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 13:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850778#M336212</guid>
      <dc:creator>Mastanvali</dc:creator>
      <dc:date>2022-12-22T13:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850781#M336215</link>
      <description>&lt;P&gt;Basic data modelling paradigm tells you that you shouldn't keep multiple values in the same column.&lt;/P&gt;
&lt;P&gt;Your post is obvious test data, but what is the real life example?&lt;/P&gt;
&lt;P&gt;My take would be to scan the columns and output each value to a new row.. Then you can remove duplicates using PROC SORT with NODUPRECS or NODUPKEY, or SQL with SELECT DISTINCT.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 13:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850781#M336215</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-12-22T13:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850783#M336216</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards4 dlm = '0a0d'x;
  input column : $ 256.;
cards4;
1,1
5,11,12,13,5,11,12
2,2,2
1,1,1,1
;;;;
run;
proc print;
run;

data want;
length element $ 20;
declare hash H(ordered:"A");
H.defineKey("element");
H.defineDone();
declare hiter I("H");

do until(eof);
  set have end=eof;
  H.CLEAR();

  if " " ne column then
    do k=1 to countw(column);
      element = scan(column,k,",");
      rc = H.add();    
    end;

  call missing(column);
  rc = I.first();
  do while (rc = 0);
    column=catx(",",column,element);
    rc = I.next();
  end;

  output;
end;

stop;
keep column;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 14:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850783#M336216</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-12-22T14:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850784#M336217</link>
      <description>&lt;P&gt;One more ("classic") approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards4 dlm = '0a0d'x;
  input column : $ 256.;
cards4;
1,1
5,11,12,13,5,11,12
2,2,2
1,1,1,1
;;;;
run;
proc print;
run;

data want0;
  set have end=eof;
  
  id+1;
  if " " ne column then
    do k=1 to countw(column);
      element = scan(column,k,",");
      output;
    end;
keep id element;
run;

proc sort data = want0 nodupkey;
  by id element;
run;

data want0;
  set want0;
  by id;
  length column $ 256;
  retain column;

  if first.ID then column="";;

  column=catx(",",column,element);

  if last.ID then output;
  keep column;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 14:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850784#M336217</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-12-22T14:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850785#M336218</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4;
input column : $ 20.;
datalines4;
1,1                
5,11,12,13,5,11,12 
2,2,2              
1,1,1,1            
;;;;

data want(keep=column newstring);
   set have;
   newstring=scan(column, 1, ',');
   do i=2 to countw(column,',');
      word=scan(column, i, ',');
      found=find(newstring, word, 'it');
      if found=0 then newstring=catx(',', newstring, word);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Dec 2022 14:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850785#M336218</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-22T14:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates from a value of the column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850936#M336283</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4;
input column : $ 20.;
datalines4;
1,1                
5,11,12,13,5,11,12 
2,2,2              
1,1,1,1            
;;;;

data want;
 set have;
 array x{999} $ 80;
 do i=1 to countw(column,',');
   temp=scan(column,i,',');
   if temp not in x then x{i}=temp;
 end;
 want=catx(',',of x{*});
 keep column want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Dec 2022 11:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-duplicates-from-a-value-of-the-column/m-p/850936#M336283</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-23T11:56:43Z</dc:date>
    </item>
  </channel>
</rss>

