<?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: Find Relative customers with different entity and similar ownership ID's (but not same) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911767#M359513</link>
    <description>&lt;P&gt;As a first step, expand those combined person_ids to multiple observations with a single person_id. From there, it is easy to formulate the join condition.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table mult as
  select distinct customer_id
  from have a, have b
  where
    a.customer_id = b.customer_id and
    a.person_id = b.person_id and
    a.entity_id ne b.entity_id
;
quit;

data want;
merge
  have (in=h)
  mult (in=m)
;
by customer_id;
value = m;
if last.customer_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Jan 2024 12:31:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-01-17T12:31:20Z</dc:date>
    <item>
      <title>Find Relative customers with different entity and similar ownership ID's (but not same)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911741#M359508</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with list of customers.&lt;/P&gt;
&lt;P&gt;For each customer there are 3 columns:&lt;/P&gt;
&lt;P&gt;Customer_ID&lt;/P&gt;
&lt;P&gt;entity_ID&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Person_IDs&amp;nbsp; (It is concatenation of people ID's who are owner )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see&amp;nbsp; specific entity can have multiple Customer_IDs&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;My target-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;For each row (Customer_ID) check if there is any other&amp;nbsp;Customer_ID with similar&amp;nbsp;Person_IDs(but not same!!) that belong to different&amp;nbsp;entity_ID . (It should be binary Var get value 1/0).&lt;/P&gt;
&lt;P&gt;When I say similar&amp;nbsp;Person_IDs I mean that at least one ID is same but not all of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also want to add another new field that&amp;nbsp; for each customer_ID&amp;nbsp; concatenate the customer_IDs that were found as similar (similar personIDs and different entity)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;For Customer_ID=1(Id's&amp;nbsp;999,888) we can see that there is another customer_ID(6) that have ownership with Id's&amp;nbsp;888 and can see that Person_IDs are not equal exactly but at least one of them is equal . so here new var will get value 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For Customer_ID=2&amp;nbsp; same like for&amp;nbsp;For Customer_ID=1&amp;nbsp; (new var will get value 1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For Customer_ID=3&amp;nbsp;new var will get value 1 because another customer (7) have similar&amp;nbsp;Person_IDs and different entity&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For customer_ID=8&amp;nbsp;new var will get value 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For customer_ID=9&amp;nbsp;new var will get value 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that in real world my data base contain 2 million rows.&lt;/P&gt;
&lt;P&gt;I thought to do cartersain&amp;nbsp; merge but i think it is not good because too many rows!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input Customer_ID  entity_ID Person_IDs $;
cards;
1 1 999,888
2 1 999,888
3 2 777
4 3 666
5 4 222,111
6 5 888
7 7 777,333
8 0 444,555
9 0 444,555
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 09:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911741#M359508</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-17T09:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find Relative customers with different entity and similar ownership ID's (but not same)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911767#M359513</link>
      <description>&lt;P&gt;As a first step, expand those combined person_ids to multiple observations with a single person_id. From there, it is easy to formulate the join condition.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table mult as
  select distinct customer_id
  from have a, have b
  where
    a.customer_id = b.customer_id and
    a.person_id = b.person_id and
    a.entity_id ne b.entity_id
;
quit;

data want;
merge
  have (in=h)
  mult (in=m)
;
by customer_id;
value = m;
if last.customer_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2024 12:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911767#M359513</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-17T12:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find Relative customers with different entity and similar ownership ID's (but not same)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911913#M359554</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input Customer_ID  entity_ID Person_IDs $;
cards;
1 1 999,888
2 1 999,888
3 2 777
4 3 666
5 4 222,111
6 5 888
7 7 777,333
8 0 444,555
9 0 444,555
;
Run;
data temp;
set have;
do i=1 to countw(Person_IDs,',');
 k=scan(Person_IDs,i,',');output;
end;
keep k entity_ID;
run;
proc sql;
create table k as
select distinct k,entity_ID as _entity_ID from temp;
quit;
data want;
 if _n_=1 then do;
  if 0 then set k;
  declare hash h(dataset:'k',multidata:'y',hashexp:20);
  h.definekey('k');
  h.definedata('_entity_ID');
  h.definedone();
 end;
set have;
want=0;
do i=1 to countw(Person_IDs,',');
 k=scan(Person_IDs,i,',');
 rc=h.find();
 do while(rc=0);
   if entity_ID ne _entity_ID then do;want=1;leave;end;
   rc=h.find_next();
 end;
 if want then leave;
end;
drop i k rc _entity_ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jan 2024 07:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Relative-customers-with-different-entity-and-similar/m-p/911913#M359554</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-18T07:04:34Z</dc:date>
    </item>
  </channel>
</rss>

