<?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: Want to write sql query to get related party account details in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923528#M363560</link>
    <description>&lt;P&gt;I suspect the problem with an SQL solution is that you have to recursively find links until no more can be found.&amp;nbsp; I.e. with every newly linked ID, you have to review the remaining obs for a even newer link by phone or email.&amp;nbsp; Result:&amp;nbsp;you would need to have a criterion within your sql code to determine that there are no more to be added.&amp;nbsp; I.e. you have to know when to stop joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have SAS/OR?&amp;nbsp; If so, then PROC OPTNET can solve the problem of recursion.&amp;nbsp; It will find all the possible links and "connected components" in the entire data set, including the components connected to your desired id (say "5534385355" in your case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do so, you have to find all links via phone number, and all links via email, as in :&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 have;
  input ID	Phone	Email :$30.;
datalines;
5534385355	385534616655	ABC@GMAIL.COM
5548558464	3588333353	ABC12.com
5564556334	6366636666	ABC2@gmail.com
554814331	     6001066401	ABC10.com
5564556331	6366636666	ABC3@gmail.com
5548558456	68136551346	ABC7.com
5538083556	6066688561	ABC4D.COM
554816644	     68141055686	ABC9.com
5563065535	6355555563486	ABC5@yahoo.com
55155355386	6460535366	ABC11.com
553438530	     385534616655	ABC1@GMAIL.COM
554884666	     6354641861	ABC13.com
5534385355	385534616655	ABC@GMAIL.COM
555336340	     6836833860	ABC6.com
554363456	     6066688561	ABC4D.COM
55464315555	6863083133	ABC8.com
556343006	     6355555563486	ABC5@yahoo.com
run;
  
proc freq data=have noprint;
  tables phone*id / out=phid (keep=phone id);
  tables email*id / out=emid (keep=email id);
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;The datasets produced by proc freq will effectively list, in order, all the ID's for each phone (in PHID), and all the ID's for each email (EMID).&amp;nbsp; From that you can create all discovered pairs:&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 pairs (keep=id1 id2 weight);
  set phid emid;
  retain weight 1;
  id1=lag(id);
  id2=id;
  if phone=lag(phone) and email=lag(email);
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;Now in the above, you might have ID=1001 connected to ID=1002, and another obs with ID=1002 connected to ID=1003.&amp;nbsp; PROC OPTNET below will know that 1003 is also connected (for your purposes) to 1001. even though there is no explicit obs stating that linkage:&amp;nbsp;&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;proc optnet data_links=pairs  out_nodes=id_nodes (rename=(node=id));
  data_link_vars  from=id1 to=id2;
  concomp;
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;The "concomp" statement tells optnet to create a connection id (concomp) that has the same value for every ID in a connected group.&amp;nbsp; Take a look at the dataset OUT_NODES it creates.&amp;nbsp; So take dataset out_nodes and get original data for the concomp that contains ID&amp;nbsp;5534385355:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  if _n_=1 then do;
    declare hash h ();
      h.definekey('id');
      h.definedata('id');
      h.definedone();
    do until (end_of_wantlist);
      merge id_nodes (where=(id=5534385355) in=wanted)
            id_nodes  end=end_of_wantlist;
      by concomp;
      if wanted then h.add();
    end;
  end;
  set have;
  if h.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2024 03:21:59 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-04-09T03:21:59Z</dc:date>
    <item>
      <title>Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923393#M363536</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;Greetings for the day!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me to write a sql to get the related party details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example suppose i have opened my account with mobile and email.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My wife has used my mobile number while opening her account and i have used my email id for my daughter's account.&lt;/P&gt;
&lt;P&gt;In this case my wife's account is related with my mobile and daughter's account is related with my email id and scenario could be daughter has used wife's email.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if i am searching for my account, i should get wife's and daughter's account as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to prepare the sample data with result output:&lt;/P&gt;
&lt;P&gt;Sample :&lt;/P&gt;
&lt;TABLE width="311"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;ID&lt;/TD&gt;
&lt;TD width="99"&gt;Phone&lt;/TD&gt;
&lt;TD width="128"&gt;Email&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5534385355&lt;/TD&gt;
&lt;TD&gt;385534616655&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC@GMAIL.COM" target="_blank"&gt;ABC@GMAIL.COM&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5548558464&lt;/TD&gt;
&lt;TD&gt;3588333353&lt;/TD&gt;
&lt;TD&gt;ABC12.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5564556334&lt;/TD&gt;
&lt;TD&gt;6366636666&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC2@gmail.com" target="_blank"&gt;ABC2@gmail.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;554814331&lt;/TD&gt;
&lt;TD&gt;6001066401&lt;/TD&gt;
&lt;TD&gt;ABC10.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5564556331&lt;/TD&gt;
&lt;TD&gt;6366636666&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC3@gmail.com" target="_blank"&gt;ABC3@gmail.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5548558456&lt;/TD&gt;
&lt;TD&gt;68136551346&lt;/TD&gt;
&lt;TD&gt;ABC7.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5538083556&lt;/TD&gt;
&lt;TD&gt;6066688561&lt;/TD&gt;
&lt;TD&gt;ABC4D.COM&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;554816644&lt;/TD&gt;
&lt;TD&gt;68141055686&lt;/TD&gt;
&lt;TD&gt;ABC9.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5563065535&lt;/TD&gt;
&lt;TD&gt;6355555563486&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC5@yahoo.com" target="_blank"&gt;ABC5@yahoo.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;55155355386&lt;/TD&gt;
&lt;TD&gt;6460535366&lt;/TD&gt;
&lt;TD&gt;ABC11.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;553438530&lt;/TD&gt;
&lt;TD&gt;385534616655&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC1@GMAIL.COM" target="_blank"&gt;ABC1@GMAIL.COM&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;554884666&lt;/TD&gt;
&lt;TD&gt;6354641861&lt;/TD&gt;
&lt;TD&gt;ABC13.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5534385355&lt;/TD&gt;
&lt;TD&gt;385534616655&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC@GMAIL.COM" target="_blank"&gt;ABC@GMAIL.COM&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;555336340&lt;/TD&gt;
&lt;TD&gt;6836833860&lt;/TD&gt;
&lt;TD&gt;ABC6.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;554363456&lt;/TD&gt;
&lt;TD&gt;6066688561&lt;/TD&gt;
&lt;TD&gt;ABC4D.COM&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;55464315555&lt;/TD&gt;
&lt;TD&gt;6863083133&lt;/TD&gt;
&lt;TD&gt;ABC8.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;556343006&lt;/TD&gt;
&lt;TD&gt;6355555563486&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC5@yahoo.com" target="_blank"&gt;ABC5@yahoo.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output :&lt;/P&gt;
&lt;TABLE width="431"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;ID&lt;/TD&gt;
&lt;TD width="99"&gt;Phone&lt;/TD&gt;
&lt;TD width="248"&gt;Email&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5534385355&lt;/TD&gt;
&lt;TD&gt;385534616655&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC@GMAIL.COM" target="_blank"&gt;ABC@GMAIL.COM&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;553438530&lt;/TD&gt;
&lt;TD&gt;385534616655&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC1@GMAIL.COM" target="_blank"&gt;ABC1@GMAIL.COM&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5564556334&lt;/TD&gt;
&lt;TD&gt;6366636666&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC2@gmail.com" target="_blank"&gt;ABC2@gmail.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5564556331&lt;/TD&gt;
&lt;TD&gt;6366636666&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC3@gmail.com" target="_blank"&gt;ABC3@gmail.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5538083556&lt;/TD&gt;
&lt;TD&gt;6066688561&lt;/TD&gt;
&lt;TD&gt;ABC4D.COM&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;554363456&lt;/TD&gt;
&lt;TD&gt;6066688561&lt;/TD&gt;
&lt;TD&gt;ABC4D.COM&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;556343006&lt;/TD&gt;
&lt;TD&gt;6355555563486&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC5@yahoo.com" target="_blank"&gt;ABC5@yahoo.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5563065535&lt;/TD&gt;
&lt;TD&gt;6355555563486&lt;/TD&gt;
&lt;TD&gt;&lt;A href="mailto:ABC5@yahoo.com" target="_blank"&gt;ABC5@yahoo.com&lt;/A&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Uma Shanker Saini&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 12:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923393#M363536</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2024-04-08T12:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923396#M363537</link>
      <description>&lt;P&gt;Is there a reason that it must be SQL and can't be a data step?&lt;/P&gt;
&lt;P&gt;Is a single query just getting a single account as input and you then want all the related accounts OR is this actually about creating networks for all of your data?&lt;/P&gt;
&lt;P&gt;How many rows do you have in your actual data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe what you really will have to do is something along the line of&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-find-all-connected-components-in-a-graph/ta-p/231539" target="_self"&gt;How to find all connected components in a graph&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 13:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923396#M363537</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-08T13:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923397#M363538</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;, I was thinking the same. A hashobject would be easier in my opinion. Otherwise with SQL I am thinking of joining the table with itself&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 12:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923397#M363538</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-04-08T12:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923399#M363539</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464333"&gt;@Mazi&lt;/a&gt;&amp;nbsp;If I understand the problem then account A and C could have no common attributes but are still linked via account B that shares attributes with both A and C ...which a single SQL self-join couldn't detect.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 12:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923399#M363539</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-08T12:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923401#M363540</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;, Agreed. I am also not entirely sure I understand the requirement/purpose here. My thinking was to have several self joins and finally transpose the columns to have them as required.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 13:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923401#M363540</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-04-08T13:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923402#M363541</link>
      <description>&lt;P&gt;Does this work?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
		(select*, count(distinct id) as gr1
			from have
				group by phone
					having gr1 gt 1)
						union corr
					(select*, count(distinct id) as gr2
				from have
			group by email
		having gr2 gt 1)
	order by email, phone, id;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2024 13:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923402#M363541</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-04-08T13:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write sql query to get related party account details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923528#M363560</link>
      <description>&lt;P&gt;I suspect the problem with an SQL solution is that you have to recursively find links until no more can be found.&amp;nbsp; I.e. with every newly linked ID, you have to review the remaining obs for a even newer link by phone or email.&amp;nbsp; Result:&amp;nbsp;you would need to have a criterion within your sql code to determine that there are no more to be added.&amp;nbsp; I.e. you have to know when to stop joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have SAS/OR?&amp;nbsp; If so, then PROC OPTNET can solve the problem of recursion.&amp;nbsp; It will find all the possible links and "connected components" in the entire data set, including the components connected to your desired id (say "5534385355" in your case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do so, you have to find all links via phone number, and all links via email, as in :&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 have;
  input ID	Phone	Email :$30.;
datalines;
5534385355	385534616655	ABC@GMAIL.COM
5548558464	3588333353	ABC12.com
5564556334	6366636666	ABC2@gmail.com
554814331	     6001066401	ABC10.com
5564556331	6366636666	ABC3@gmail.com
5548558456	68136551346	ABC7.com
5538083556	6066688561	ABC4D.COM
554816644	     68141055686	ABC9.com
5563065535	6355555563486	ABC5@yahoo.com
55155355386	6460535366	ABC11.com
553438530	     385534616655	ABC1@GMAIL.COM
554884666	     6354641861	ABC13.com
5534385355	385534616655	ABC@GMAIL.COM
555336340	     6836833860	ABC6.com
554363456	     6066688561	ABC4D.COM
55464315555	6863083133	ABC8.com
556343006	     6355555563486	ABC5@yahoo.com
run;
  
proc freq data=have noprint;
  tables phone*id / out=phid (keep=phone id);
  tables email*id / out=emid (keep=email id);
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;The datasets produced by proc freq will effectively list, in order, all the ID's for each phone (in PHID), and all the ID's for each email (EMID).&amp;nbsp; From that you can create all discovered pairs:&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 pairs (keep=id1 id2 weight);
  set phid emid;
  retain weight 1;
  id1=lag(id);
  id2=id;
  if phone=lag(phone) and email=lag(email);
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;Now in the above, you might have ID=1001 connected to ID=1002, and another obs with ID=1002 connected to ID=1003.&amp;nbsp; PROC OPTNET below will know that 1003 is also connected (for your purposes) to 1001. even though there is no explicit obs stating that linkage:&amp;nbsp;&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;proc optnet data_links=pairs  out_nodes=id_nodes (rename=(node=id));
  data_link_vars  from=id1 to=id2;
  concomp;
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;The "concomp" statement tells optnet to create a connection id (concomp) that has the same value for every ID in a connected group.&amp;nbsp; Take a look at the dataset OUT_NODES it creates.&amp;nbsp; So take dataset out_nodes and get original data for the concomp that contains ID&amp;nbsp;5534385355:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  if _n_=1 then do;
    declare hash h ();
      h.definekey('id');
      h.definedata('id');
      h.definedone();
    do until (end_of_wantlist);
      merge id_nodes (where=(id=5534385355) in=wanted)
            id_nodes  end=end_of_wantlist;
      by concomp;
      if wanted then h.add();
    end;
  end;
  set have;
  if h.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 03:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-write-sql-query-to-get-related-party-account-details/m-p/923528#M363560</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-04-09T03:21:59Z</dc:date>
    </item>
  </channel>
</rss>

