<?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 Links in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264704#M51969</link>
    <description>&lt;P&gt;So&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;node: 1-&amp;gt;3-&amp;gt;5-&amp;gt;4&lt;/P&gt;
&lt;P&gt;score : &amp;nbsp; &amp;nbsp;8-&amp;gt;10-&amp;gt;7&amp;nbsp;&lt;/P&gt;
&lt;P&gt;7 less than 10 ,therefore drop 4 ,right ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: change my code &amp;nbsp;&lt;/P&gt;
&lt;P&gt;multidata&amp;amp;colon;'y'&lt;/P&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;P&gt;m........ta : 'y'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems this forum run into some problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATED&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards expandtabs truncover ;&lt;BR /&gt;input from $ to $ score ;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 8&lt;BR /&gt;1 3 8&lt;BR /&gt;3 5 10&lt;BR /&gt;5 4 7&lt;BR /&gt;4 6 8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt; if _n_ eq 1 then do;&lt;BR /&gt; if 0 then set have(rename=(score=_score));&lt;BR /&gt; declare hash k(dataset:'have(rename=(score=_score)');&lt;BR /&gt; k.definekey('from');&lt;BR /&gt; k.definedata('_score');&lt;BR /&gt; k.definedone();&lt;BR /&gt; &lt;BR /&gt; declare hash h();&lt;BR /&gt; h.definekey('drop');&lt;BR /&gt; h.definedata('drop');&lt;BR /&gt; h.definedone();&lt;BR /&gt; end;&lt;BR /&gt;set have end=last; &lt;BR /&gt; _score=.;&lt;BR /&gt; rc=k.find(key:to);&lt;BR /&gt; if _score lt score and not missing(_score) then do;drop=to;h.replace();end;&lt;BR /&gt; if last then h.output(dataset:'drop_obs');&lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;data full; &lt;BR /&gt; if _n_ eq 1 then do;&lt;BR /&gt; if 0 then set drop_obs;&lt;BR /&gt; declare hash k(dataset:'drop_obs');&lt;BR /&gt; k.definekey('drop');&lt;BR /&gt; k.definedone();&lt;BR /&gt; &lt;BR /&gt; declare hash h();&lt;BR /&gt; h.definekey('node');&lt;BR /&gt; h.definedata('node');&lt;BR /&gt; h.definedone();&lt;BR /&gt; end;&lt;BR /&gt;set have end=last;&lt;BR /&gt;if k.check(key:from) ne 0 then output;&lt;BR /&gt; node=from; h.replace();&lt;BR /&gt; from=to; to=node;&lt;BR /&gt;if k.check(key:to) ne 0 then output;&lt;BR /&gt; node=from; h.replace();&lt;BR /&gt;&lt;BR /&gt; if last then h.output(dataset:'node');&lt;BR /&gt; drop node drop score;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want(keep=node household);&lt;BR /&gt;declare hash ha(ordered:'a');&lt;BR /&gt;declare hiter hi('ha');&lt;BR /&gt;ha.definekey('count');&lt;BR /&gt;ha.definedata('last');&lt;BR /&gt;ha.definedone();&lt;BR /&gt;declare hash _ha(hashexp: 20);&lt;BR /&gt;_ha.definekey('key');&lt;BR /&gt;_ha.definedone();&lt;BR /&gt;&lt;BR /&gt;if 0 then set full;&lt;BR /&gt;declare hash from_to(dataset:'full(where=(from is not missing &lt;BR /&gt; and to is not missing ))',&lt;BR /&gt; hashexp:20,multidata&amp;amp;colon;'y');&lt;BR /&gt; from_to.definekey('from');&lt;BR /&gt; from_to.definedata('to');&lt;BR /&gt; from_to.definedone();&lt;BR /&gt;&lt;BR /&gt;if 0 then set node;&lt;BR /&gt;declare hash no(dataset:'node');&lt;BR /&gt;declare hiter hi_no('no');&lt;BR /&gt; no.definekey('node');&lt;BR /&gt; no.definedata('node');&lt;BR /&gt; no.definedone();&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;do while(hi_no.next()=0);&lt;BR /&gt; household+1; output;&lt;BR /&gt; count=1;&lt;BR /&gt; key=node;_ha.add();&lt;BR /&gt; last=node;ha.add();&lt;BR /&gt; rc=hi.first();&lt;BR /&gt; do while(rc=0);&lt;BR /&gt; from=last;rx=from_to.find();&lt;BR /&gt; do while(rx=0);&lt;BR /&gt; key=to;ry=_ha.check();&lt;BR /&gt; if ry ne 0 then do;&lt;BR /&gt; node=to;output;rr=no.remove(key:node);&lt;BR /&gt; key=to;_ha.add();&lt;BR /&gt; count+1;&lt;BR /&gt; last=to;ha.add();&lt;BR /&gt; end;&lt;BR /&gt; rx=from_to.find_next();&lt;BR /&gt; end;&lt;BR /&gt; rc=hi.next();&lt;BR /&gt;end;&lt;BR /&gt;ha.clear();_ha.clear();&lt;BR /&gt;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2016 02:54:36 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-04-19T02:54:36Z</dc:date>
    <item>
      <title>Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264475#M51872</link>
      <description>&lt;P&gt;I would like to seek your expert advice how do i attain the result table by using the source. I would want to group the ids which are linked together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see here id 5 is actually both linked to id 1 and 4, but the score of the link between 1 and 5 is higher. Reason that on the desired result it 5 will be under group 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greatly appreciate your inputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data source;
input id1 id2 score;	
datalines;
1	2	8
1	3	8
3	5	10
5	4	7
4	6	8
;
		
		
data result;		
input group	id;
datalines;
1	1	
1	2	
1	3	
1	5	
2	4	
2	6	
;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2016 04:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264475#M51872</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2016-04-18T04:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264492#M51880</link>
      <description>&lt;P&gt;Why would 4 and 6 go into another group ? because 7 &amp;lt; 8 ?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 07:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264492#M51880</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-18T07:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264509#M51887</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16582"&gt;@milts﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Recently, I contributed&amp;nbsp;some code to&amp;nbsp;a discussion of a very similar question (except that no scores were involved there). Please see the thread &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Recursive-lookup-for-ID-s/m-p/259988" target="_blank"&gt;Recursive lookup for ID's&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 09:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264509#M51887</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-18T09:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264694#M51967</link>
      <description>&lt;P&gt;Yes, The id will go to the group where it has a higher score in it.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 23:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264694#M51967</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2016-04-18T23:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264704#M51969</link>
      <description>&lt;P&gt;So&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;node: 1-&amp;gt;3-&amp;gt;5-&amp;gt;4&lt;/P&gt;
&lt;P&gt;score : &amp;nbsp; &amp;nbsp;8-&amp;gt;10-&amp;gt;7&amp;nbsp;&lt;/P&gt;
&lt;P&gt;7 less than 10 ,therefore drop 4 ,right ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: change my code &amp;nbsp;&lt;/P&gt;
&lt;P&gt;multidata&amp;amp;colon;'y'&lt;/P&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;P&gt;m........ta : 'y'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems this forum run into some problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATED&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards expandtabs truncover ;&lt;BR /&gt;input from $ to $ score ;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 8&lt;BR /&gt;1 3 8&lt;BR /&gt;3 5 10&lt;BR /&gt;5 4 7&lt;BR /&gt;4 6 8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt; if _n_ eq 1 then do;&lt;BR /&gt; if 0 then set have(rename=(score=_score));&lt;BR /&gt; declare hash k(dataset:'have(rename=(score=_score)');&lt;BR /&gt; k.definekey('from');&lt;BR /&gt; k.definedata('_score');&lt;BR /&gt; k.definedone();&lt;BR /&gt; &lt;BR /&gt; declare hash h();&lt;BR /&gt; h.definekey('drop');&lt;BR /&gt; h.definedata('drop');&lt;BR /&gt; h.definedone();&lt;BR /&gt; end;&lt;BR /&gt;set have end=last; &lt;BR /&gt; _score=.;&lt;BR /&gt; rc=k.find(key:to);&lt;BR /&gt; if _score lt score and not missing(_score) then do;drop=to;h.replace();end;&lt;BR /&gt; if last then h.output(dataset:'drop_obs');&lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;data full; &lt;BR /&gt; if _n_ eq 1 then do;&lt;BR /&gt; if 0 then set drop_obs;&lt;BR /&gt; declare hash k(dataset:'drop_obs');&lt;BR /&gt; k.definekey('drop');&lt;BR /&gt; k.definedone();&lt;BR /&gt; &lt;BR /&gt; declare hash h();&lt;BR /&gt; h.definekey('node');&lt;BR /&gt; h.definedata('node');&lt;BR /&gt; h.definedone();&lt;BR /&gt; end;&lt;BR /&gt;set have end=last;&lt;BR /&gt;if k.check(key:from) ne 0 then output;&lt;BR /&gt; node=from; h.replace();&lt;BR /&gt; from=to; to=node;&lt;BR /&gt;if k.check(key:to) ne 0 then output;&lt;BR /&gt; node=from; h.replace();&lt;BR /&gt;&lt;BR /&gt; if last then h.output(dataset:'node');&lt;BR /&gt; drop node drop score;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want(keep=node household);&lt;BR /&gt;declare hash ha(ordered:'a');&lt;BR /&gt;declare hiter hi('ha');&lt;BR /&gt;ha.definekey('count');&lt;BR /&gt;ha.definedata('last');&lt;BR /&gt;ha.definedone();&lt;BR /&gt;declare hash _ha(hashexp: 20);&lt;BR /&gt;_ha.definekey('key');&lt;BR /&gt;_ha.definedone();&lt;BR /&gt;&lt;BR /&gt;if 0 then set full;&lt;BR /&gt;declare hash from_to(dataset:'full(where=(from is not missing &lt;BR /&gt; and to is not missing ))',&lt;BR /&gt; hashexp:20,multidata&amp;amp;colon;'y');&lt;BR /&gt; from_to.definekey('from');&lt;BR /&gt; from_to.definedata('to');&lt;BR /&gt; from_to.definedone();&lt;BR /&gt;&lt;BR /&gt;if 0 then set node;&lt;BR /&gt;declare hash no(dataset:'node');&lt;BR /&gt;declare hiter hi_no('no');&lt;BR /&gt; no.definekey('node');&lt;BR /&gt; no.definedata('node');&lt;BR /&gt; no.definedone();&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;do while(hi_no.next()=0);&lt;BR /&gt; household+1; output;&lt;BR /&gt; count=1;&lt;BR /&gt; key=node;_ha.add();&lt;BR /&gt; last=node;ha.add();&lt;BR /&gt; rc=hi.first();&lt;BR /&gt; do while(rc=0);&lt;BR /&gt; from=last;rx=from_to.find();&lt;BR /&gt; do while(rx=0);&lt;BR /&gt; key=to;ry=_ha.check();&lt;BR /&gt; if ry ne 0 then do;&lt;BR /&gt; node=to;output;rr=no.remove(key:node);&lt;BR /&gt; key=to;_ha.add();&lt;BR /&gt; count+1;&lt;BR /&gt; last=to;ha.add();&lt;BR /&gt; end;&lt;BR /&gt; rx=from_to.find_next();&lt;BR /&gt; end;&lt;BR /&gt; rc=hi.next();&lt;BR /&gt;end;&lt;BR /&gt;ha.clear();_ha.clear();&lt;BR /&gt;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 02:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264704#M51969</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-19T02:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264778#M51986</link>
      <description>&lt;P&gt;Cool! Couldn't thank you enough as this really helps a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But let's say removing the score, and I just want to get the linkings how do i implement it using hash objects?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So given the data sample links:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1-&amp;gt;2&lt;/P&gt;&lt;P&gt;1-&amp;gt;3&lt;/P&gt;&lt;P&gt;3-&amp;gt;5&lt;/P&gt;&lt;P&gt;5-&amp;gt;4&lt;/P&gt;&lt;P&gt;4-&amp;gt;6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What portion of the code below should I tweak so that the result of this links is that they will fall under the same household?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;All wil&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 13:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264778#M51986</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2016-04-19T13:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264790#M51990</link>
      <description>&lt;P&gt;I guess you're example here works for me. Let me try this one out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Recursive-lookup-for-ID-s/td-p/259635/page/3" target="_self"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Recursive-lookup-for-ID-s/td-p/259635/page/3&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 14:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264790#M51990</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2016-04-19T14:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264960#M52032</link>
      <description>&lt;P&gt;That would lead to a more simple question.&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;
infile cards ;
input from $  to $ ;
cards;
1 2
1 3
3 5
5 4
4 6
;
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&amp;amp;colon;'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, 20 Apr 2016 00:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264960#M52032</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-20T00:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering Links</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264991#M52038</link>
      <description>&lt;P&gt;Thanks a lot! This really cut down my script from running for a day to a couple of minutes!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 03:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering-Links/m-p/264991#M52038</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2016-04-20T03:20:28Z</dc:date>
    </item>
  </channel>
</rss>

