<?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: Grouping pairs into groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38423#M7718</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to know whether these obs is populated in the dataset randomly? there some obs maybe at the end of dataset . look like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pair1 Pair2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it were so. I have coded it for a user ------- sas_Forum.&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://communities.sas.com/104261#104261"&gt;http://communities.sas.com/message/104261#104261&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Art297. I found the link is not available any more . Why ? because sas_Forum has deleted it?&lt;/P&gt;&lt;P&gt;Fortunately I have a copy.&lt;/P&gt;&lt;P&gt;The following code is an example for your question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data test;
input&amp;nbsp; ( pan1 pan2 pan3 add1&amp;nbsp; ) ($);
datalines;
aaa&amp;nbsp;&amp;nbsp; bbb&amp;nbsp;&amp;nbsp;&amp;nbsp; ccc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddd&amp;nbsp;&amp;nbsp;&amp;nbsp; 
. . . .
qqq&amp;nbsp;&amp;nbsp; rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; www&amp;nbsp;&amp;nbsp; aaa&amp;nbsp;&amp;nbsp; 
rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ppp&amp;nbsp;&amp;nbsp;&amp;nbsp; mmm lll&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
uuu&amp;nbsp;&amp;nbsp; zzz&amp;nbsp;&amp;nbsp;&amp;nbsp; ffff&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ppp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
p&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n
. . . .
. . . .
jjjj&amp;nbsp;&amp;nbsp;&amp;nbsp; eee&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ooo&amp;nbsp;&amp;nbsp;&amp;nbsp; 
sss&amp;nbsp;&amp;nbsp; www&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eee 
;
run;

 

options compress=yes;
data want(keep=pan1 pan2 pan3 add1 household);
/*to make speed faster*/
 declare hash ha(hashexp : 20,ordered : 'a');
 declare hiter hi('ha');
&amp;nbsp; ha.definekey('count');
&amp;nbsp; ha.definedata('count','pan1','pan2','pan3','add1');
&amp;nbsp; ha.definedone();
 declare hash _ha(hashexp: 20,ordered : 'a');
&amp;nbsp; _ha.definekey('key');
&amp;nbsp; _ha.definedone();

do until(last);
 set test end=last; 
/*Remove obs which variable's are all missing firstly*/
 if cmiss(pan1,pan2,pan3,add1) lt 4 then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.add();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
end;

length key $ 40;
array h{4} $ 40 pan1 pan2 pan3 add1;
/*copy the first obs from Hash Table HA into PDV*/
_rc=hi.first();
do while(_rc eq 0); *until the end of Hash Table HA;
/*assign a unique cluster flag(i.e. household)*/
 household+1;
 do i=1 to 4;
/*push not missing value of current obs into another Hash Table _HA*/
&amp;nbsp;&amp;nbsp; if not missing(h{i}) then do; key=h{i}; _ha.replace();end;
 end;&amp;nbsp;&amp;nbsp; 
/*start to run over Hash Table HA ,until can not find any more 
 observation which is the same cluster with current observation*/
 do until(x=1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; x=1;
/*copy the first obs from Hash Table HA into PDV*/
&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.first();
&amp;nbsp;&amp;nbsp;&amp;nbsp; do while(rc=0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to 4;
/*find whether any one of value is included in the current obs*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=h{j};rcc=_ha.check();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rcc =0 then found=1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found then do;
/*if any one of value is included,then push the obs which is copied from
Hash Table HA into Hash Tables _HA,flag it the same cluster with the 
current obs and output it into dataset*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do k=1 to 4;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(h{k}) then do; key=h{k};_ha.replace();end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;x=0; _count=count;*keep this found obs's index; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.next();
/*remove the found obs from Hash Table HA,since it has been seared*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found then rx=ha.remove(key : _count);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
 end;
/*clear up all the index which is the same cluster with the current obs*/ 
 _ha.clear();
/*copy the first obs from Hash Table HA into PDV*/
_rc=hi.first();
end; 
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Nov 2011 05:33:12 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-11-01T05:33:12Z</dc:date>
    <item>
      <title>Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38418#M7713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;Dear All,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;I need to group pairs into groups / clusters.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;For instance, in the following table:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="padding-bottom: 0px; padding-left: 5.4pt; padding-right: 5.4pt; margin-left: 4.65pt; padding-top: 0px;" width="128"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;Pair1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;Pair2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;The first 3 rows will be in the same cluster because they all have one pair in common and the cluster will then include pairs 1, 2, 3 and 4.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;The last row will be in a different cluster because pairs 5 and 6 are not in any other row.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;The final dataset will then be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="padding-bottom: 0px; padding-left: 5.4pt; padding-right: 5.4pt; margin-left: 4.65pt; padding-top: 0px;" width="192"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;Pair1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;Pair2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;Cluster&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" style="padding-left: 5.4pt; padding-right: 5.4pt;" valign="bottom" width="64"&gt;&lt;P align="center"&gt;&lt;SPAN style="font-family: Arial; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;I’ve written a code that works well but it’s inefficient (it uses a lot of memory and it's slow): when the input dataset is bigger than 50,000 pairs it goes in memory overflow.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;Any help would be really appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial; color: #333333; font-size: 10pt;"&gt;Thanks a lot in advance&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 15:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38418#M7713</guid>
      <dc:creator>Giamma14</dc:creator>
      <dc:date>2011-10-31T15:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38419#M7714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;looks like a job for a hash table&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 15:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38419#M7714</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-10-31T15:22:24Z</dc:date>
    </item>
    <item>
      <title>Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38420#M7715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know hash table, could you please address me on the right topic or provide me an example?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 16:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38420#M7715</guid>
      <dc:creator>Giamma14</dc:creator>
      <dc:date>2011-10-31T16:39:29Z</dc:date>
    </item>
    <item>
      <title>Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38421#M7716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at that different approaches suggested in the following thread: &lt;A _jive_internal="true" href="https://communities.sas.com/message/104329#104329"&gt;http://communities.sas.com/message/104329#104329&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A hash approach is included in one of the suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 16:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38421#M7716</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-31T16:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38422#M7717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you are doing graph analysis. You want to get the connected sub-graphs. Here is a simplified version of a macro I did years ago for this.&amp;nbsp; Not sure how fast it is, but it will work as long as your disk is large enough. I think this version might be for directed graphs.&amp;nbsp; You could either fix the selection logic to check both directions or just duplicate your data with the values of pair1/pair2 flipped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;%macro &lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;subnet(in=,out=,from=from,to=to,subnet=subnet);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;/*----------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;SUBNET - Build connected subnets from pairs of nodes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Input Table :FROM TO pairs of rows&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Output Table:input data with &amp;amp;subnet added&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Work Tables: &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; NODES - List of all nodes in input.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; NEW - List of new nodes to assign to current subnet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Algorithm:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Pick next unassigned node and grow the subnet by adding all connected &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;nodes. Repeat until all unassigned nodes are put into a subnet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;----------------------------------------------------------------------*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%local &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;subnetid next getnext ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Put code to get next unassigned node into macro variable because it is&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;used in two places in the program.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;-----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%let &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;getnext= select node into :next from nodes where subnet=.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%&lt;/SPAN&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;Initialize subnet id counter.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;-----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%let &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;subnetid=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Get list of all nodes ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; create table nodes as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;. &lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;as subnet, &amp;amp;from as node from &amp;amp;in&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; union&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;. &lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;as subnet, &amp;amp;to as node from &amp;amp;in&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Get next unassigned node ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &amp;amp;getnext;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%do &lt;/SPAN&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%while&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; (&amp;amp;sqlobs) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Set subnet to next id ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp; &lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%let &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;subnetid=&lt;/SPAN&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%eval&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;(&amp;amp;subnetid+1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; update nodes set subnet=&amp;amp;subnetid where node=&amp;amp;next;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp; &lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%do &lt;/SPAN&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%while&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; (&amp;amp;sqlobs) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Get list of connected nodes for this subnet ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table new as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;amp;to as node&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;amp;in a, nodes b, nodes c&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;amp;from= b.node&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;amp;to= c.node&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and b.subnet = &amp;amp;subnetid&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and c.subnet = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Update subnet for these nodes ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; update nodes set subnet=&amp;amp;subnetid&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where node in&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select node from new )&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp; &lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Get next unassigned node ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &amp;amp;getnext;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;* Create output dataset by adding subnet number. ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: green; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*----------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; create table &amp;amp;out as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*,b.subnet as &amp;amp;subnet&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;amp;in a , nodes b&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;amp;from = b.node&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;%mend &lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;subnet ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data &lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;in;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp; &lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;input &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;pair1 pair2 @@;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: #ffffc0; font-family: 'Courier New'; font-size: 10pt;"&gt;1 2 1 3 2 4 5 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;subnet&lt;/EM&gt;&lt;/STRONG&gt;(in=in,out=out,from=pair1,to=pair2,subnet=group);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;proc &lt;/SPAN&gt;&lt;SPAN style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;print&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;=out;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; pair1&amp;nbsp;&amp;nbsp;&amp;nbsp; pair2&amp;nbsp;&amp;nbsp;&amp;nbsp; group&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 21:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38422#M7717</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-31T21:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping pairs into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38423#M7718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to know whether these obs is populated in the dataset randomly? there some obs maybe at the end of dataset . look like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pair1 Pair2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it were so. I have coded it for a user ------- sas_Forum.&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://communities.sas.com/104261#104261"&gt;http://communities.sas.com/message/104261#104261&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Art297. I found the link is not available any more . Why ? because sas_Forum has deleted it?&lt;/P&gt;&lt;P&gt;Fortunately I have a copy.&lt;/P&gt;&lt;P&gt;The following code is an example for your question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data test;
input&amp;nbsp; ( pan1 pan2 pan3 add1&amp;nbsp; ) ($);
datalines;
aaa&amp;nbsp;&amp;nbsp; bbb&amp;nbsp;&amp;nbsp;&amp;nbsp; ccc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddd&amp;nbsp;&amp;nbsp;&amp;nbsp; 
. . . .
qqq&amp;nbsp;&amp;nbsp; rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; www&amp;nbsp;&amp;nbsp; aaa&amp;nbsp;&amp;nbsp; 
rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ppp&amp;nbsp;&amp;nbsp;&amp;nbsp; mmm lll&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
uuu&amp;nbsp;&amp;nbsp; zzz&amp;nbsp;&amp;nbsp;&amp;nbsp; ffff&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ppp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
p&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n
. . . .
. . . .
jjjj&amp;nbsp;&amp;nbsp;&amp;nbsp; eee&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rrr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ooo&amp;nbsp;&amp;nbsp;&amp;nbsp; 
sss&amp;nbsp;&amp;nbsp; www&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eee 
;
run;

 

options compress=yes;
data want(keep=pan1 pan2 pan3 add1 household);
/*to make speed faster*/
 declare hash ha(hashexp : 20,ordered : 'a');
 declare hiter hi('ha');
&amp;nbsp; ha.definekey('count');
&amp;nbsp; ha.definedata('count','pan1','pan2','pan3','add1');
&amp;nbsp; ha.definedone();
 declare hash _ha(hashexp: 20,ordered : 'a');
&amp;nbsp; _ha.definekey('key');
&amp;nbsp; _ha.definedone();

do until(last);
 set test end=last; 
/*Remove obs which variable's are all missing firstly*/
 if cmiss(pan1,pan2,pan3,add1) lt 4 then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ha.add();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
end;

length key $ 40;
array h{4} $ 40 pan1 pan2 pan3 add1;
/*copy the first obs from Hash Table HA into PDV*/
_rc=hi.first();
do while(_rc eq 0); *until the end of Hash Table HA;
/*assign a unique cluster flag(i.e. household)*/
 household+1;
 do i=1 to 4;
/*push not missing value of current obs into another Hash Table _HA*/
&amp;nbsp;&amp;nbsp; if not missing(h{i}) then do; key=h{i}; _ha.replace();end;
 end;&amp;nbsp;&amp;nbsp; 
/*start to run over Hash Table HA ,until can not find any more 
 observation which is the same cluster with current observation*/
 do until(x=1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; x=1;
/*copy the first obs from Hash Table HA into PDV*/
&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.first();
&amp;nbsp;&amp;nbsp;&amp;nbsp; do while(rc=0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to 4;
/*find whether any one of value is included in the current obs*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=h{j};rcc=_ha.check();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rcc =0 then found=1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found then do;
/*if any one of value is included,then push the obs which is copied from
Hash Table HA into Hash Tables _HA,flag it the same cluster with the 
current obs and output it into dataset*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do k=1 to 4;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(h{k}) then do; key=h{k};_ha.replace();end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;x=0; _count=count;*keep this found obs's index; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.next();
/*remove the found obs from Hash Table HA,since it has been seared*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found then rx=ha.remove(key : _count);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
 end;
/*clear up all the index which is the same cluster with the current obs*/ 
 _ha.clear();
/*copy the first obs from Hash Table HA into PDV*/
_rc=hi.first();
end; 
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Nov 2011 05:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-pairs-into-groups/m-p/38423#M7718</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-11-01T05:33:12Z</dc:date>
    </item>
  </channel>
</rss>

