<?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: Creating family IDs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433154#M107374</link>
    <description>&lt;P&gt;Are you adding children to your current data set? I ask because consider this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You start with&lt;/P&gt;
&lt;P&gt;A1, Y1, X1&lt;/P&gt;
&lt;P&gt;A2, Y1, X1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A5, Y3, X2&lt;/P&gt;
&lt;P&gt;A6, Y3, X2&lt;/P&gt;
&lt;P&gt;(two simple family structures and you assign 2 ids)&lt;/P&gt;
&lt;P&gt;later you add this child:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A10, Y1,X2&lt;/P&gt;
&lt;P&gt;Which existing family would this go to? Reassigning existing ID would very likely be a very poor process. But your "rule" says A10 is associated with both of the existing "families".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you don't mention the ages of the children involved so what about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A230, A5,X10&lt;/P&gt;
&lt;P&gt;where your "children" are also parents?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While there many reasons to have single variables for simple code there are times when they can complicate other logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there are some procedures actually deal with pairs such as mother/fathe. Proc Inbreed is one.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 16:03:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-02-01T16:03:27Z</dc:date>
    <item>
      <title>Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433024#M107312</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I'm doing research on some data which contains information on children and their parents. I would like to create an ID number for each family/entity. The tricky part (or at least for me) is that children should be given the same ID number if they are somehow linked through their parents. As an example the six children below (A1-A6) should all be given the same ID number, as (1) the first four children (A1-A4) have the same father, (2) A5 is&amp;nbsp;a halfsibling to A4 (they have the same mother) and (3) A6 is a halfsibling to A5 (the have the same father) &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Child ID, Mother ID, Father ID&lt;/P&gt;&lt;P&gt;A1, Y1, X1&lt;/P&gt;&lt;P&gt;A2, Y1, X1&lt;/P&gt;&lt;P&gt;A3, Y2, X1&amp;nbsp;&lt;/P&gt;&lt;P&gt;A4, Y3, X1&lt;/P&gt;&lt;P&gt;A5, Y3, X2&lt;/P&gt;&lt;P&gt;A6, Y4, X2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope someone can help me figure this out. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 07:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433024#M107312</guid>
      <dc:creator>CharlotteH</dc:creator>
      <dc:date>2018-02-01T07:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433036#M107319</link>
      <description>&lt;P&gt;I think you will have to figure out your requirements correctly first.&lt;/P&gt;&lt;P&gt;Take data like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Child_ID $ Mother_ID $ Father_ID $;
cards;
A1 Y1 X1
A2 Y1 X1
A3 Y2 X1&amp;nbsp;
A4 Y3 X1
A5 Y3 X2
A6 Y4 X2
A7 Y5 X2
A8 Y5 X3
;run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;According to your rule, A5 and A7 should have the same family ID, because they have the same father. And A7 and A8 should have the same family ID because they have the same mother. So A5 and A8 will end up with the same family ID, even though they have no parents in common. Is this really what you want?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 08:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433036#M107319</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-02-01T08:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433039#M107321</link>
      <description>&lt;P&gt;Exactely. I know it sounds a bit strange, but for the purpose I'm working on at the moment that's what I want. &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 08:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433039#M107321</guid>
      <dc:creator>CharlotteH</dc:creator>
      <dc:date>2018-02-01T08:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433091#M107344</link>
      <description>&lt;P&gt;OK. How about this one ?&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;
 Y1 A1
 X1 A1
Y1 A2 
X1 A2 
Y2 A3
X1 A3
Y3 A4
X1 A4
Y3 A5
X2 A5
Y4 A6 
X2 A6
;
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, 01 Feb 2018 12:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433091#M107344</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-01T12:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433102#M107349</link>
      <description>&lt;P&gt;Here is shorter hash version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Child_ID $ Mother_ID $ Father_ID $;
cards;
A1 Y1 X1
A2 Y1 X1
A3 Y2 X1 
A4 Y3 X1
A5 Y3 X2
A6 Y4 X2
A7 Y5 X2
A8 Y5 X3
A9 Y6 X4
;
run;

data want;
   if _n_ = 1 then do;
      cid = 0;
      if 0 then set have;
      declare hash hm();
      hm.definekey('Mother_ID');
      hm.definedone();
      declare hash hf();
      hf.definekey('Father_ID');
      hf.definedone();
   end;
   set have;
   rm = hm.find();
   rf = hf.find();
   if rm ^= 0 then hm.add();
   if rf ^= 0 then hf.add();
   if (rm ^= 0 &amp;amp; rf ^= 0) then cid+1;
drop rm rf;
run;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 13:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433102#M107349</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-02-01T13:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating family IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433154#M107374</link>
      <description>&lt;P&gt;Are you adding children to your current data set? I ask because consider this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You start with&lt;/P&gt;
&lt;P&gt;A1, Y1, X1&lt;/P&gt;
&lt;P&gt;A2, Y1, X1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A5, Y3, X2&lt;/P&gt;
&lt;P&gt;A6, Y3, X2&lt;/P&gt;
&lt;P&gt;(two simple family structures and you assign 2 ids)&lt;/P&gt;
&lt;P&gt;later you add this child:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A10, Y1,X2&lt;/P&gt;
&lt;P&gt;Which existing family would this go to? Reassigning existing ID would very likely be a very poor process. But your "rule" says A10 is associated with both of the existing "families".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you don't mention the ages of the children involved so what about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A230, A5,X10&lt;/P&gt;
&lt;P&gt;where your "children" are also parents?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While there many reasons to have single variables for simple code there are times when they can complicate other logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there are some procedures actually deal with pairs such as mother/fathe. Proc Inbreed is one.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-family-IDs/m-p/433154#M107374</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-01T16:03:27Z</dc:date>
    </item>
  </channel>
</rss>

