<?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 Find all customers that are related each other in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-all-customers-that-are-related-each-other/m-p/839577#M331954</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say that there is a data set called "Have" that contain 2 columns : IP (identity number ) and customer ID.&lt;/P&gt;
&lt;P&gt;As you can see specific customer can have multiple owners (Multiple IP's ).&lt;/P&gt;
&lt;P&gt;Specific IP can be belonged to multiple customers (Multiple customer ID that IP belong to ).&lt;/P&gt;
&lt;P&gt;My target:&lt;/P&gt;
&lt;P&gt;I want to know for each customer_ID what are the other customer_ID's&amp;nbsp; that are related.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Under customer_ID&amp;nbsp; 7777777 there are 3 IP's (1,2,3)&lt;/P&gt;
&lt;P&gt;IP 1 belong also to customer_ID 8888888&lt;/P&gt;
&lt;P&gt;IP 3 belong also to customer_ID 9999999&lt;/P&gt;
&lt;P&gt;So the conclusion is that customer_ID 77777777 is related to customer_ID's&amp;nbsp; &amp;nbsp;88888888,99999999&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input IP customer_ID ;
cards;
1 7777777
1 8888888
2 7777777
3 7777777
3 9999999
;
Run;
proc sort data=have;by IP ;Run;
proc transpose data=have out=have2(drop=_NAME_) prefix=customer_ID;
by IP ;
var customer_ID;
run;


Data want1;
Input customer_ID other_customer_ID1 other_customer_ID2;
cards;
7777777 8888888 9999999
8888888 7777777
9999999 7777777
;
Run;


Data want2;
Input customer_ID other_customer;
cards;
7777777 8888888 
7777777 9999999
8888888 7777777
9999999 7777777
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Oct 2022 05:57:27 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-10-20T05:57:27Z</dc:date>
    <item>
      <title>Find all customers that are related each other</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-all-customers-that-are-related-each-other/m-p/839577#M331954</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say that there is a data set called "Have" that contain 2 columns : IP (identity number ) and customer ID.&lt;/P&gt;
&lt;P&gt;As you can see specific customer can have multiple owners (Multiple IP's ).&lt;/P&gt;
&lt;P&gt;Specific IP can be belonged to multiple customers (Multiple customer ID that IP belong to ).&lt;/P&gt;
&lt;P&gt;My target:&lt;/P&gt;
&lt;P&gt;I want to know for each customer_ID what are the other customer_ID's&amp;nbsp; that are related.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Under customer_ID&amp;nbsp; 7777777 there are 3 IP's (1,2,3)&lt;/P&gt;
&lt;P&gt;IP 1 belong also to customer_ID 8888888&lt;/P&gt;
&lt;P&gt;IP 3 belong also to customer_ID 9999999&lt;/P&gt;
&lt;P&gt;So the conclusion is that customer_ID 77777777 is related to customer_ID's&amp;nbsp; &amp;nbsp;88888888,99999999&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input IP customer_ID ;
cards;
1 7777777
1 8888888
2 7777777
3 7777777
3 9999999
;
Run;
proc sort data=have;by IP ;Run;
proc transpose data=have out=have2(drop=_NAME_) prefix=customer_ID;
by IP ;
var customer_ID;
run;


Data want1;
Input customer_ID other_customer_ID1 other_customer_ID2;
cards;
7777777 8888888 9999999
8888888 7777777
9999999 7777777
;
Run;


Data want2;
Input customer_ID other_customer;
cards;
7777777 8888888 
7777777 9999999
8888888 7777777
9999999 7777777
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Oct 2022 05:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-all-customers-that-are-related-each-other/m-p/839577#M331954</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-10-20T05:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find all customers that are related each other</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-all-customers-that-are-related-each-other/m-p/839607#M331960</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards ;
input from $  to $ ;
cards;
1 7777777
1 8888888
2 7777777
3 7777777
3 9999999
;
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>Thu, 20 Oct 2022 11:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-all-customers-that-are-related-each-other/m-p/839607#M331960</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-20T11:40:11Z</dc:date>
    </item>
  </channel>
</rss>

