<?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 How to de-dup/find unique values in the same cell? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227072#M54145</link>
    <description>&lt;P&gt;I have Group and Cities columns in my dataset, and some of the cities are duplicates. I want to find the unique cities. How can I code that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Group&lt;/TD&gt;&lt;TD&gt;Cities&lt;/TD&gt;&lt;TD&gt;Unique Cities&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Houston, Houston, New York, Los Angeles, Los Angeles&lt;/TD&gt;&lt;TD&gt;Houstin, New York, Los Angeles&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Chicago, Boston, Boston&lt;/TD&gt;&lt;TD&gt;Chicago, Boston&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;Miami, Worcester, Worcester, Springfield, Springfield, Atlanta, Atlanta&lt;/TD&gt;&lt;TD&gt;Miami, Worcester, Springfield, Atlanta&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;Oakland, Oakland, Oakland, Dallas, Dallas&lt;/TD&gt;&lt;TD&gt;Oakland, Dallas&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;Lancaster, Boston, Madison, Madison, Madison, Madison&lt;/TD&gt;&lt;TD&gt;Lancaster, Boston, Madison&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Thu, 24 Sep 2015 14:32:00 GMT</pubDate>
    <dc:creator>ernie86</dc:creator>
    <dc:date>2015-09-24T14:32:00Z</dc:date>
    <item>
      <title>How to de-dup/find unique values in the same cell?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227072#M54145</link>
      <description>&lt;P&gt;I have Group and Cities columns in my dataset, and some of the cities are duplicates. I want to find the unique cities. How can I code that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Group&lt;/TD&gt;&lt;TD&gt;Cities&lt;/TD&gt;&lt;TD&gt;Unique Cities&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Houston, Houston, New York, Los Angeles, Los Angeles&lt;/TD&gt;&lt;TD&gt;Houstin, New York, Los Angeles&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Chicago, Boston, Boston&lt;/TD&gt;&lt;TD&gt;Chicago, Boston&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;Miami, Worcester, Worcester, Springfield, Springfield, Atlanta, Atlanta&lt;/TD&gt;&lt;TD&gt;Miami, Worcester, Springfield, Atlanta&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;Oakland, Oakland, Oakland, Dallas, Dallas&lt;/TD&gt;&lt;TD&gt;Oakland, Dallas&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;Lancaster, Boston, Madison, Madison, Madison, Madison&lt;/TD&gt;&lt;TD&gt;Lancaster, Boston, Madison&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 24 Sep 2015 14:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227072#M54145</guid>
      <dc:creator>ernie86</dc:creator>
      <dc:date>2015-09-24T14:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to de-dup/find unique values in the same cell?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227103#M54146</link>
      <description>&lt;P&gt;Here's a rough version, for the final I would add some macros so you don't have to know how many cities their are, macro variables should be able to take care of that and shorten the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd dlm='*';&lt;BR /&gt;informat group $1. cities $100.;&lt;BR /&gt;input group$ cities$;&lt;BR /&gt;cards;&lt;BR /&gt;A*Houston, Houston, New York, Los Angeles, Los Angeles&lt;BR /&gt;B*Chicago, Boston, Boston&lt;BR /&gt;C*Miami, Worcester, Worcester, Springfield, Springfield, Atlanta, Atlanta&lt;BR /&gt;D*Oakland, Oakland, Oakland, Dallas, Dallas&lt;BR /&gt;E*Lancaster, Boston, Madison, Madison, Madison, Madison&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data start;&lt;BR /&gt;set have;&lt;BR /&gt;comma=countc(cities,',')+1;&lt;BR /&gt;scan1=strip(scan(cities,comma-0,','));&lt;BR /&gt;scan2=strip(scan(cities,comma-1,','));&lt;BR /&gt;scan3=strip(scan(cities,comma-2,','));&lt;BR /&gt;scan4=strip(scan(cities,comma-3,','));&lt;BR /&gt;scan5=strip(scan(cities,comma-4,','));&lt;BR /&gt;scan6=strip(scan(cities,comma-5,','));&lt;BR /&gt;scan7=strip(scan(cities,comma-6,','));&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=start out=tran(drop=_NAME_);by group;var scan:;&lt;BR /&gt;&lt;BR /&gt;proc sort data=tran nodup;by group col1;where not missing(col1);&lt;BR /&gt;&lt;BR /&gt;proc transpose data=tran out=tran2(drop=_NAME_);by group;var col1;&lt;BR /&gt;&lt;BR /&gt;data want(keep=group unique);&lt;BR /&gt;set tran2;&lt;BR /&gt;unique=catx(',',of col1-col4);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 15:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227103#M54146</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-24T15:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to de-dup/find unique values in the same cell?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227116#M54148</link>
      <description>&lt;P&gt;A single pass with a data step will work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   length unique $ 100;
   do i = 1 to countw(cities,',');
      if indexw(unique,scan(cities,i,','))=0 then unique=catx(', ',unique,scan(cities,i,','));
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The Unique variable should have the same length as the cities variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 16:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-de-dup-find-unique-values-in-the-same-cell/m-p/227116#M54148</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-09-24T16:17:10Z</dc:date>
    </item>
  </channel>
</rss>

