<?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: Clustering with an Incidence Matrix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718900#M222525</link>
    <description>&lt;P&gt;Challenge to the next poster on this topic.&amp;nbsp; Offer example data referring to this site's coverage of the same topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Get-a-list-of-all-relationships/m-p/708406" target="_blank" rel="noopener"&gt;Solved: Get a list of all relationships - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688087" target="_blank" rel="noopener"&gt;Solved: Is family construction possible? - SAS Support Communities&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2021 17:55:56 GMT</pubDate>
    <dc:creator>PhilC</dc:creator>
    <dc:date>2021-02-12T17:55:56Z</dc:date>
    <item>
      <title>Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718008#M222128</link>
      <description>&lt;P&gt;I have data serialized by a variable N, and I have a dataset that is virtually an incidence matrix.&amp;nbsp; How might I find the eleven (11) groupings of records in HAVE that are connected to common undirected graphs defined by the&amp;nbsp;incidence_matrix dataset?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caveats:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I only have SAS STAT.&amp;nbsp; Using any other SAS package is not an option, but please include your idea anyway.&lt;/LI&gt;
&lt;LI&gt;Do not assume big data.&amp;nbsp; Expect less than 10k rows for HAVE in real life, and a matrix about as sparse.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  do N=1 to 15;
    output;
  end;
stop;

data incidence_matrix(index=(N));
  input N N2;
datalines;
1 2
2 10
5 6
5 7
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;want&lt;/STRONG&gt;:&amp;nbsp; a column that groups the records.&amp;nbsp; (Answering &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;) User should be able to perform sorts and use by statements with the new column.&amp;nbsp; An example dataset:&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;N&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="border-left: none; width: 48pt;"&gt;X&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;2&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;3&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;4&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;5&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;6&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;7&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;8&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;9&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;10&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-top: none; border-left: none; width: 48pt;"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" align="right" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;15&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl65" style="border-left: none; width: 48pt;"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 13:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718008#M222128</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-10T13:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718022#M222131</link>
      <description>What do you expect as output from this as input?</description>
      <pubDate>Tue, 09 Feb 2021 21:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718022#M222131</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-09T21:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718203#M222225</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  do N=1 to 15;
    output;
  end;
stop;
run;
data incidence_matrix(index=(N));
  input N N2;
datalines;
1 2
2 10
5 6
5 7
;
run;
data have;
 set have incidence_matrix;
 rename n=from n2=to;
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, 10 Feb 2021 12:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718203#M222225</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-10T12:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718681#M222449</link>
      <description>&lt;P&gt;Thanks for your time&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&amp;nbsp; Hash tables are probably the best way to do this given all of my limitations, but, more than this, the coders I work here with are not ready for hash tables, to be honest.&amp;nbsp; I want to avoid it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I did. My original problem was a time period overlap problem, and I had experience working in other platforms with graph theory and network propagation so I found my self asking this question.&amp;nbsp; &lt;A href="https://communities.sas.com/t5/SAS-Programming/Combine-overlapping-dates-while-keeping-non-continuous-intervals/m-p/718280#M222260" target="_self"&gt;Work&lt;/A&gt; you did with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;in September &lt;EM&gt;2019&lt;/EM&gt; helped me in the end.&amp;nbsp; thanks again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 20:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718681#M222449</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-12T20:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718853#M222510</link>
      <description>&lt;P&gt;If you don't like hash table. I remembered&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; wrote a macro about it . searching it at this communities.&lt;/P&gt;
&lt;P&gt;Or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;know it also .&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 11:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718853#M222510</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-12T11:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718855#M222512</link>
      <description>&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"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-find-all-connected-components-in-a-graph/ta-p/231539&lt;/A&gt;</description>
      <pubDate>Fri, 12 Feb 2021 11:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718855#M222512</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-12T11:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718900#M222525</link>
      <description>&lt;P&gt;Challenge to the next poster on this topic.&amp;nbsp; Offer example data referring to this site's coverage of the same topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Get-a-list-of-all-relationships/m-p/708406" target="_blank" rel="noopener"&gt;Solved: Get a list of all relationships - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688087" target="_blank" rel="noopener"&gt;Solved: Is family construction possible? - SAS Support Communities&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 17:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718900#M222525</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-12T17:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering with an Incidence Matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718950#M222538</link>
      <description>SAS/OR BOM also offers a solution.</description>
      <pubDate>Fri, 12 Feb 2021 17:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-with-an-Incidence-Matrix/m-p/718950#M222538</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-12T17:15:52Z</dc:date>
    </item>
  </channel>
</rss>

