<?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: Links Analysis: Identify Unique Networks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880907#M348073</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You want this ?
If you have SAS/OR, the code could be more compact and less.
*/
data have;
infile cards ;
input from $  to $ ;
cards;
1     2
1     3
4     5
5     2
9     4
6     7
8     7
;
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, 15 Jun 2023 12:27:07 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-06-15T12:27:07Z</dc:date>
    <item>
      <title>Links Analysis: Identify Unique Networks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880871#M348055</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a methodology to identify "Unique" Networks. Example Below:&lt;/P&gt;&lt;P&gt;1. Let's assume I have the connection between "From" and "To":&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;From&lt;/TD&gt;&lt;TD&gt;To&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I'd be happy to build a program that identifies that the first 4 lines belongs to Network 1, and the last 2 lines belongs to Network 2. These 2 Networks are disconnected from each other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;From&lt;/TD&gt;&lt;TD&gt;To&lt;/TD&gt;&lt;TD&gt;Network&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 08:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880871#M348055</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2023-06-15T08:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Links Analysis: Identify Unique Networks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880879#M348059</link>
      <description>&lt;P&gt;So it appears that&amp;nbsp;&lt;A href="https://github.com/sasutils" target="_blank" rel="author noopener"&gt;sasutils&lt;/A&gt; solved it using the subnet.sas macro here:&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/subnet.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/subnet.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 09:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880879#M348059</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2023-06-15T09:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Links Analysis: Identify Unique Networks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880885#M348061</link>
      <description>&lt;P&gt;Interesting. Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68241"&gt;@DanielDor&lt;/a&gt;, for providing the link. So, that's a PROC SQL approach. Other options include &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/ornoaug/ornoaug_optnet_overview.htm" target="_blank" rel="noopener"&gt;PROC OPTNET&lt;/A&gt; (SAS/OR) as recommended in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Create-clusters-from-pairs/m-p/205905/highlight/true#M38280" target="_blank" rel="noopener"&gt;Re: Create clusters from pairs&lt;/A&gt; and, requiring only Base SAS, DATA step (hash object) approaches as presented in the&amp;nbsp;Communities Library article &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-find-all-connected-components-in-a-graph/ta-p/231539" target="_blank" rel="noopener"&gt;How to find all connected components in a graph&lt;/A&gt;: the SubGraphs macro by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462" target="_blank" rel="noopener"&gt;PGStats&lt;/A&gt; and the code provided by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408" target="_blank" rel="noopener"&gt;KSharp&lt;/A&gt; in his comment.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 09:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880885#M348061</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-06-15T09:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Links Analysis: Identify Unique Networks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880907#M348073</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You want this ?
If you have SAS/OR, the code could be more compact and less.
*/
data have;
infile cards ;
input from $  to $ ;
cards;
1     2
1     3
4     5
5     2
9     4
6     7
8     7
;
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, 15 Jun 2023 12:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Links-Analysis-Identify-Unique-Networks/m-p/880907#M348073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-06-15T12:27:07Z</dc:date>
    </item>
  </channel>
</rss>

