<?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 check duplicate customer IDs using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420551#M280648</link>
    <description>&lt;P&gt;This can be solved using Hash, however, make sure you don't have infinite loops, if you do, set a&amp;nbsp;loop limit&amp;nbsp;(say the total number of your obs), when reached, exit the loop regardless.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 ID2
;
cards;
11     22
22     35
35     9
41     10
52     87
9       65
;

run;

data want;
if _n_=1 then do;
dcl hash h(dataset:'work.have');
h.definekey('id1');
h.definedata(all:'y');
h.definedone();
call missing(id1, id2);
end;

set have(rename=(id1=_id1 id2=_id2));
length id3 $20.;
rc=0;
id1=_id1;
do while (rc=0);
rc=h.find();
id1=id2;
end;
id3=catx('_', 'ID', PUT(id1,BEST.));
KEEP ID3 _id:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Dec 2017 18:42:50 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2017-12-12T18:42:50Z</dc:date>
    <item>
      <title>How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420546#M280647</link>
      <description>&lt;P&gt;I have a dataset in sas like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1 ID2&lt;/P&gt;
&lt;P&gt;11 22&lt;BR /&gt;11 34&lt;BR /&gt;22 35&lt;BR /&gt;35 9&lt;BR /&gt;41 10&lt;BR /&gt;52 87&lt;BR /&gt;9 65&lt;BR /&gt;34 43&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to check for ID1 vs ID2 assignent, and find duplicate IDs, e.g. 11 is assigned to 22 and then 11&amp;gt;&amp;gt;34,22 &amp;gt;&amp;gt;35, 35&amp;gt;&amp;gt;9,9&amp;gt;&amp;gt;65 and &lt;SPAN&gt;34 &amp;gt;&amp;gt; 43&lt;/SPAN&gt;&amp;nbsp;. So all these IDs should be mapped to single ID, say 11(we can choose any of them). I want to create a 3rd variable, where I will assign all values to a single ID say ID_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so Final output will be like:&lt;/P&gt;
&lt;P&gt;ID1&amp;nbsp;&amp;nbsp; ID2&amp;nbsp; &amp;nbsp; ID3&lt;/P&gt;
&lt;P&gt;11 &amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_11&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;11 &amp;nbsp; &amp;nbsp; 34 &amp;nbsp; &amp;nbsp;&amp;nbsp;ID_11&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_11&lt;/P&gt;
&lt;P&gt;35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_11&lt;/P&gt;
&lt;P&gt;41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_10&lt;/P&gt;
&lt;P&gt;52&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_87&lt;/P&gt;
&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 65&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID_11&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;34 &amp;nbsp; &amp;nbsp; 43 &amp;nbsp; &amp;nbsp;&amp;nbsp;ID_11&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I found out that, its a disjoint set problem. how to do this using sas?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 11:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420546#M280647</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-13T11:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420551#M280648</link>
      <description>&lt;P&gt;This can be solved using Hash, however, make sure you don't have infinite loops, if you do, set a&amp;nbsp;loop limit&amp;nbsp;(say the total number of your obs), when reached, exit the loop regardless.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 ID2
;
cards;
11     22
22     35
35     9
41     10
52     87
9       65
;

run;

data want;
if _n_=1 then do;
dcl hash h(dataset:'work.have');
h.definekey('id1');
h.definedata(all:'y');
h.definedone();
call missing(id1, id2);
end;

set have(rename=(id1=_id1 id2=_id2));
length id3 $20.;
rc=0;
id1=_id1;
do while (rc=0);
rc=h.find();
id1=id2;
end;
id3=catx('_', 'ID', PUT(id1,BEST.));
KEEP ID3 _id:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Dec 2017 18:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420551#M280648</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-12-12T18:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420555#M280649</link>
      <description>&lt;P&gt;Can we make these assumptions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;ID1 and ID2 are character&lt;/LI&gt;
&lt;LI&gt;ID1 maps to a single ID2 value only, never to two different ID2 values&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If that's the case, the programming is easy enough:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;fmtname='$test';&lt;/P&gt;
&lt;P&gt;rename id1=start id2=label;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format cntlin=temp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;length id3 id4 $ 5;&lt;/P&gt;
&lt;P&gt;id3 = put(id1, $test.);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;id4 = id3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;do i=1 to 500 until (id3 = id4);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;if id3 ne id4 then id3 = id4;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; id4 = put(id3, $test.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;id3 = 'ID_' || id3;&lt;/P&gt;
&lt;P&gt;drop i&amp;nbsp;&amp;nbsp;id4;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;EDITED to add the missing lines.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 19:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420555#M280649</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-12T19:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420722#M280650</link>
      <description>&lt;P&gt;sorry, There could be duplicate mapping in ID1, I updated the example case&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420722#M280650</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-13T10:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420726#M280651</link>
      <description>sorry, There could be duplicate mapping in ID1, I updated the example case,</description>
      <pubDate>Wed, 13 Dec 2017 10:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420726#M280651</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-13T10:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420769#M280652</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards ;
input from $  to $ ;
cards;
11 22
11 34
22 35
35 9
41 10
52 87
9 65
34 43
;
run;
data full;
  set have end=last;
  if _n_ eq 1 then do;
   declare hash h();
    h.definekey('node');
     h.definedata('node');
     h.definedone();
  end;
  output;
  node=from; h.replace();
  from=to; to=node;
  output;
  node=from; h.replace();
  if last then h.output(dataset:'node');
  drop node;
run;


data want(keep=node household);
declare hash ha(ordered:'a');
declare hiter hi('ha');
ha.definekey('count');
ha.definedata('last');
ha.definedone();
declare hash _ha(hashexp: 20);
_ha.definekey('key');
_ha.definedone();

if 0 then set full;
declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
 from_to.definekey('from');
 from_to.definedata('to');
 from_to.definedone();

if 0 then set node;
declare hash no(dataset:'node');
declare hiter hi_no('no');
 no.definekey('node');
 no.definedata('node');
 no.definedone();
 

do while(hi_no.next()=0);
 household+1; output;
 count=1;
 key=node;_ha.add();
 last=node;ha.add();
 rc=hi.first();
 do while(rc=0);
   from=last;rx=from_to.find();
   do while(rx=0);
     key=to;ry=_ha.check();
      if ry ne 0 then do;
       node=to;output;rr=no.remove(key:node);
       key=to;_ha.add();
       count+1;
       last=to;ha.add();
      end;
      rx=from_to.find_next();
   end;
   rc=hi.next();
end;
ha.clear();_ha.clear();
end;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 13:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420769#M280652</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-13T13:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420776#M280653</link>
      <description>Thanks for your effort. Is there any alternative where we can avoid declaring hash?</description>
      <pubDate>Wed, 13 Dec 2017 13:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420776#M280653</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-13T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420790#M280654</link>
      <description>&lt;P&gt;Sorry. I am afraid you have to use Hash Table to search tree.&lt;/P&gt;
&lt;P&gt;Or you could write some SAS/OR code, but you need SAS/OR.&lt;/P&gt;
&lt;P&gt;And post your question at OR forum,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;is there .&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 14:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420790#M280654</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-13T14:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420833#M280655</link>
      <description>&lt;P&gt;No, we don;t have SAS/OR. Can it be done using arrays? I saw a solution, but not sure how that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data unique_id;
      set x end = last;
      /*Create an array to store mapping and intitialize array*/
      array mapping{&amp;amp;n_obs,2} _temporary_;
      if _N_ = 1 then
      do;
      do i = 1 to &amp;amp;n_obs.;
                  
            mapping[i,1] = i;
            mapping[i,2] = i;
      end;
      end;
      /*Create an array to store pr_row_num and row_num*/
      array lookup{2} row_num pr_row_num;
        orig_val1 = mapping[lookup[1],2];
      orig_val2 = mapping[lookup[2],2];
      max_val = max(row_num,pr_row_num);
      replaced_val = min(lookup[1],lookup[2],mapping[lookup[1],2],mapping[lookup[2],2]);
      /*Loop through the mapping file and change orig_val1 or orig_val2 in the mapping array to replaced_val*/
      do i = 1 to &amp;amp;n_obs.;
            if mapping[i,2] = orig_val1 or mapping[i,2] = orig_val2 then
            mapping[i,2] = replaced_val;
      end;

      if last;
      do i = 1 to &amp;amp;n_obs.;
            key1 = mapping[i,1];
            key2 = mapping[i,2];
            output;
      end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 15:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420833#M280655</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-13T15:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420923#M280656</link>
      <description>&lt;P&gt;This functionality is called "connected components" and is available in:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;PROC OPTNET or PROC OPTMODEL in SAS/OR&lt;/LI&gt;
&lt;LI&gt;PROC OPTGRAPH in SAS Social Network Analysis&lt;/LI&gt;
&lt;LI&gt;PROC NETWORK in SAS Visual Data Mining and Machine Learning (Viya)&lt;/LI&gt;
&lt;LI&gt;PROC OPTNETWORK or PROC OPTMODEL in SAS&amp;nbsp;Optimization (Viya)&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 13 Dec 2017 18:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/420923#M280656</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2017-12-13T18:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421151#M280657</link>
      <description>&lt;P&gt;Sorry. As far as I know, must Hash Table, no choice.&lt;/P&gt;
&lt;P&gt;Or you could switch into SAS/OR ,just as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;said.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 12:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421151#M280657</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-14T12:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421399#M280658</link>
      <description>&lt;P&gt;Edited on 12/15.&amp;nbsp; Thanks to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15140"&gt;@Matthew_Galati&lt;/a&gt;, I've revised the program and my comments.&amp;nbsp; Please ignore all the text is &lt;STRONG&gt;&lt;STRIKE&gt;strikethrough&lt;/STRIKE&gt;&lt;/STRONG&gt; font.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have SAS/OR, you can get this directly by asking PROC OPTNET for "connected components".&amp;nbsp; It becomes a trivial task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID1 ID2;
  &lt;STRIKE&gt;retain w 1;&lt;/STRIKE&gt;
datalines;
11 22
11 34
22 35
35 9
41 10
52 87
9 65
34 43
run;


proc optnet data_links=have (rename=(id1=from id2=to &lt;STRIKE&gt;w=weight&lt;/STRIKE&gt;))
      graph_direction=undirected out_nodes=nodes ;
  concomp;&lt;BR /&gt;  shortpath out_weights=shdist;
run;

proc sql;
  create table want as
  select h.*, n.concomp from
  have as h left join nodes as n
  on h.id1=n.node;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRIKE&gt;I had to add a "weight" variable (var w) to dataset HAVE,&amp;nbsp;which proc optnet uses as the "distance" between ID1 and ID2 (optnet is commonly used to generate the shortest distances between all pairs of connected nodes (id's in your case).&amp;nbsp; As long as W is a non-missing numeric value, it works for your problem, because you care about connectivity, not distance.&amp;nbsp; Of course if your constant W value is 1, then the "distance" is the number of hopes from ID2 to ID2.&lt;/STRIKE&gt;&lt;BR /&gt;&lt;BR /&gt;Because, in the absence of a weight variable (thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15140"&gt;@Matthew_Galati&lt;/a&gt;), the default&amp;nbsp;"distance" from ID2 to ID1 is taken as 1.&amp;nbsp; As a result the variable &lt;EM&gt;&lt;STRONG&gt;path_weight&lt;/STRONG&gt;&lt;/EM&gt; in SHDIST is just the number of hops from ID2 to SOURCE.&amp;nbsp;&amp;nbsp;Here's what the 1st 20 obs in SHDIST data set looks like:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path_&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs source sink weight&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp; &amp;nbsp;11&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp; 34&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp; &amp;nbsp;35&amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;9&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp; &amp;nbsp;65&amp;nbsp;&amp;nbsp; &amp;nbsp;4&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;6&amp;nbsp;&amp;nbsp; &amp;nbsp;11&amp;nbsp;&amp;nbsp; &amp;nbsp;43&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;7&amp;nbsp;&amp;nbsp; &amp;nbsp;22&amp;nbsp;&amp;nbsp; &amp;nbsp;11&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;9&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; &amp;nbsp;35&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;10&amp;nbsp;&amp;nbsp; &amp;nbsp;22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;11&amp;nbsp;&amp;nbsp; &amp;nbsp;22&amp;nbsp;&amp;nbsp; &amp;nbsp;65&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;12&amp;nbsp;&amp;nbsp; &amp;nbsp;22&amp;nbsp;&amp;nbsp; &amp;nbsp;43&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;13&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;14&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;15&amp;nbsp;&amp;nbsp;&amp;nbsp; 34&amp;nbsp; &amp;nbsp; 35&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;16&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;9&amp;nbsp;&amp;nbsp; &amp;nbsp;4&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;17&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp; &amp;nbsp;65&amp;nbsp;&amp;nbsp; &amp;nbsp;5&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;18&amp;nbsp;&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp; &amp;nbsp;43&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;19&amp;nbsp;&amp;nbsp; &amp;nbsp;35&amp;nbsp;&amp;nbsp; &amp;nbsp;11&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;20&amp;nbsp;&amp;nbsp; &amp;nbsp;35&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;/LI&gt;
&lt;LI&gt;The "concomp" statement asks proc optnet to assign each node (id) to a connected-component identifier.&amp;nbsp; In your case here's, what the&amp;nbsp;"nodes" dataset looks like:
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs node concomp&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;11&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;2&amp;nbsp;&amp;nbsp; 22&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;3&amp;nbsp; &amp;nbsp;34&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;4&amp;nbsp;&amp;nbsp; 35&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;5&amp;nbsp;&amp;nbsp; &amp;nbsp;9&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;6&amp;nbsp; &amp;nbsp;41&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;7&amp;nbsp; &amp;nbsp;10&amp;nbsp;&amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;8&amp;nbsp;&amp;nbsp; 52&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;9&amp;nbsp; &amp;nbsp;87&amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;10&amp;nbsp; &amp;nbsp;65&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;11&amp;nbsp; &amp;nbsp;43&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;/LI&gt;
&lt;LI&gt;And the resulting dataset WANT:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    ID1    ID2    w    concomp

 1       9     65    1       1
 2      11     22    1       1
 3      11     34    1       1
 4      22     35    1       1
 5      34     43    1       1
 6      35      9    1       1
 7      41     10    1       2
 8      52     87    1       3










&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 15 Dec 2017 18:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421399#M280658</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-15T18:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421429#M280659</link>
      <description>&lt;P&gt;If you know that all your id values are&amp;nbsp;integers in some range (say from 1 through 100), you actually can do this with an array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID1 ID2;
datalines;
11 22
11 34
22 35
35  9
41 10
52 87
9  65
34 43
run;
data want;
  array src {100} _temporary_;
  if _n_=1 then do until (eod);
    set have end=eod;
    src{id2}=id1;
  end;

  set have ;
  source=id1;
  do Nlinks=1 by 1 while (src{source}^=.);
    source=src{source};
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caveat:&amp;nbsp; This depends on each sequence of links going to a final source.&amp;nbsp; I.e. no collections of links forms a repeating cycle.&amp;nbsp; The program would require some minor changes to deal with cycles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The 1-dimensional array SRC has the value of ID1 corresponding to the ID2 element of the array.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;For each pair ID1 is treated as the source, and ID2 as the sink.&amp;nbsp; The program iteratively finds the source of a source, until an id without a source is encountered.&amp;nbsp; For example,&amp;nbsp;SRC{11} is a missing value, even though SRC{22}=11&amp;nbsp; (as well as others).&lt;/LI&gt;
&lt;LI&gt;The variable Nlinks is the number of links required to go from ID2 to the ultimate source.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 15 Dec 2017 04:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421429#M280659</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-15T04:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421543#M280660</link>
      <description>&lt;P&gt;You do not need to add&amp;nbsp;the weight variable for optnet shortest path to get the 'level'. Unweighted graphs assume unit weights on all edges.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 13:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421543#M280660</guid>
      <dc:creator>Matthew_Galati</dc:creator>
      <dc:date>2017-12-15T13:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to check duplicate customer IDs using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421944#M280661</link>
      <description>Thanks. The solution is simply elegant and simple</description>
      <pubDate>Mon, 18 Dec 2017 11:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-duplicate-customer-IDs-using-SAS/m-p/421944#M280661</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2017-12-18T11:27:45Z</dc:date>
    </item>
  </channel>
</rss>

