<?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: MACRO SAS to build a pedigree of specific individuals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/302252#M312312</link>
    <description>&lt;PRE&gt;
Sure. I take individual=16 as an example.



data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
;
run;

data have;
 if _n_=1 then do;
  if 0 then set one;
  declare hash h(dataset:'one');
  h.definekey('individual');
  h.definedone();
 end;
set one;
output;
_sire=sire;
_dam=dam;
if h.check(key:_sire) ne 0 then do;
 individual=_sire;
 h.add();
 sire=0;
 dam=0;
 sex=1;
 birth_year=.;
 output;
end;
if h.check(key:_dam) ne 0 then do;
 individual=_dam;
 h.add();
 sire=0;
 dam=0;
 sex=2;
 birth_year=.;
 output;
end;
drop _:;
run;

data key;
 set one;
 from=individual;to=sire;output;
 to=dam;output;
 keep from to;
run;


data full;
  set key 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;

%let individual=16;
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(where=(node=&amp;amp;individual))');
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;



data final_want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
end;
call missing(of _all_);
set want;
 individual=node;
 h.find();
run;

&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Oct 2016 05:40:31 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-10-04T05:40:31Z</dc:date>
    <item>
      <title>MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300648#M312301</link>
      <description>&lt;P&gt;Hello, i am new in the community;&lt;/P&gt;
&lt;P&gt;i need a macro in SAS (but I have no experience) that meets the following function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From a genealogy file (example):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;I would like to search the complete genealogy (all possible kinship relationships) for one or more specific individuals (specified by me)&lt;/STRONG&gt;, so in theory the file should be as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg. if looking for the complete genealogy of the individual 13:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;individual sire	dam    sex	birth_year
3	1	2	1	2005
4	0	0	2	.
7	0	0	1	.
8	0	0	2	.
10	3	4	2	2010
11	7	8	1	2011
13	11	10	1	2014&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Well, I hope we can help me.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Alan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2016 23:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300648#M312301</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-09-25T23:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300677#M312302</link>
      <description>&lt;PRE&gt;
So you only care about its Fathers or Mothers ?


data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
;
run;

data have;
 if _n_=1 then do;
  if 0 then set one;
  declare hash h(dataset:'one');
  h.definekey('individual');
  h.definedone();
 end;
set one;
output;
_sire=sire;
_dam=dam;
if h.check(key:_sire) ne 0 then do;
 individual=_sire;
 h.add();
 sire=0;
 dam=0;
 sex=1;
 birth_year=.;
 output;
end;
if h.check(key:_dam) ne 0 then do;
 individual=_dam;
 h.add();
 sire=0;
 dam=0;
 sex=2;
 birth_year=.;
 output;
end;
drop _:;
run;

data key;
 set one;
 start=individual;end=sire;output;
 end=dam;output;
 keep start end;
run;


data want;
 
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
 
  if 0 then set key;
  declare hash k(dataset:'key',multidata:'y');
  k.definekey('start');
  k.definedata('end');
  k.definedone();
  
  declare hash path(ordered:'y');
  declare hiter hi_pa('path');
  path.definekey('n');
  path.definedata('last');
  path.definedone();

individual=13; /*&amp;lt;-----*/
n=1;
path.add(key:n,data:individual);

do while(hi_pa.next()=0);
 individual=last;
 if h.find()=0 then output;
 
 _last=last;
 rc=k.find(key:_last);
 do while(rc=0);
  n+1;last=end;path.add();
  rc=k.find_next(key:_last);
 end;
 
end;
stop;
drop rc last _last n start end;
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2016 02:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300677#M312302</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-26T02:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300753#M312303</link>
      <description>&lt;P&gt;Hi Ksharp,&amp;nbsp;it works!&amp;nbsp;thank you very much!!&lt;/P&gt;&lt;P&gt;I do not want to abuse your generosity, but I do another question:&lt;BR /&gt;- If I want to search more than one individual (block individuals, for example 16 and 13), this code works?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S.: I do not understand your question about fathers and mothers...&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 13:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300753#M312303</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-09-26T13:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300788#M312304</link>
      <description>&lt;P&gt;If you are working with similar data frequently you may want to investigate Proc Inbreed.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 15:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300788#M312304</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-26T15:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300961#M312305</link>
      <description>&lt;PRE&gt;
Change it :
individual=16;

And combine them together into one table.

I mean you only care about its ancients , don't care about its offspring or brothers ?

&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 09:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300961#M312305</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-27T09:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300978#M312306</link>
      <description>&lt;PRE&gt;
OK. Here is .






data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
;
run;

data have;
 if _n_=1 then do;
  if 0 then set one;
  declare hash h(dataset:'one');
  h.definekey('individual');
  h.definedone();
 end;
set one;
output;
_sire=sire;
_dam=dam;
if h.check(key:_sire) ne 0 then do;
 individual=_sire;
 h.add();
 sire=0;
 dam=0;
 sex=1;
 birth_year=.;
 output;
end;
if h.check(key:_dam) ne 0 then do;
 individual=_dam;
 h.add();
 sire=0;
 dam=0;
 sex=2;
 birth_year=.;
 output;
end;
drop _:;
run;

data key;
 set one;
 start=individual;end=sire;output;
 end=dam;output;
 keep start end;
run;

proc sql; /*&amp;lt;-------------------------*/
create table individual as 
 select distinct start as id
  from key
   where start in (13 16);
quit;
 

data want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
 
  if 0 then set key;
  declare hash k(dataset:'key',multidata:'y');
  k.definekey('start');
  k.definedata('end');
  k.definedone();
  
  declare hash path(ordered:'y');
  declare hiter hi_pa('path');
  path.definekey('n');
  path.definedata('last');
  path.definedone();
end;
set individual;
individual=id; /*&amp;lt;-----*/
n=1;
path.add(key:n,data:individual);

do while(hi_pa.next()=0);
 individual=last;
 if h.find()=0 then output;
 
 _last=last;
 rc=k.find(key:_last);
 do while(rc=0);
  n+1;last=end;path.add();
  rc=k.find_next(key:_last);
 end;
 
end;
path.clear();
drop rc last _last n start end;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 10:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/300978#M312306</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-27T10:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301034#M312307</link>
      <description>&lt;P&gt;it works! Thank you!&lt;/P&gt;&lt;P&gt;Now I understand your question about the fathers and mothers.&lt;/P&gt;&lt;P&gt;It's very interesting your point of view about incorporating descendants and siblings. But it is not proposed because it seemed complicated to do.&lt;/P&gt;&lt;P&gt;But you think you can achieve some code that includes descencientes in the search?&lt;BR /&gt;Concerning the siblings, note that is a population of cattle and there are full siblings (sons of the same sire and dam) and half-&lt;SPAN&gt;siblings&lt;/SPAN&gt; (sons of the same sire&amp;nbsp;but not the same dam, and vice versa).&lt;/P&gt;&lt;P&gt;What do you say, can be done?&lt;/P&gt;&lt;P&gt;Thanks!&lt;BR /&gt;Alan&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 14:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301034#M312307</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-09-27T14:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301199#M312308</link>
      <description>&lt;PRE&gt;
"But you think you can achieve some code that includes descencientes in the search?"
Yes. I can make that happened include full siblings and  half-siblings .

BTW, My code would not work if you have bad data (a dead loop) Like:

id  Father Mother
1   2   3
2   4   5
5   1   6

1-&amp;gt;2-&amp;gt;5-&amp;gt;1

But I can fixed it though.
&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2016 10:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301199#M312308</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-28T10:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301223#M312309</link>
      <description>&lt;P&gt;Ok. Sorry, but I do not entirely understand what a dead loop ?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 11:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301223#M312309</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-09-28T11:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301257#M312310</link>
      <description>&lt;PRE&gt;
If you have the data as I showed you .
You will got this forever .  My code will pending there and never finished.

1-&amp;gt;2-&amp;gt;5-&amp;gt; 1-&amp;gt;2-&amp;gt;5-&amp;gt; 1-&amp;gt;2-&amp;gt;5 -&amp;gt;1-&amp;gt;2-&amp;gt;5 -&amp;gt;1-&amp;gt;2-&amp;gt;5 -&amp;gt;1-&amp;gt;2-&amp;gt;5-&amp;gt;1............ forever..


&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/301257#M312310</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-28T13:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/302024#M312311</link>
      <description>Ok!&lt;BR /&gt;Will I can give a clue how to include both descendants as well full siblings and half-siblings?&lt;BR /&gt;Thanks!</description>
      <pubDate>Mon, 03 Oct 2016 12:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/302024#M312311</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-10-03T12:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/302252#M312312</link>
      <description>&lt;PRE&gt;
Sure. I take individual=16 as an example.



data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
;
run;

data have;
 if _n_=1 then do;
  if 0 then set one;
  declare hash h(dataset:'one');
  h.definekey('individual');
  h.definedone();
 end;
set one;
output;
_sire=sire;
_dam=dam;
if h.check(key:_sire) ne 0 then do;
 individual=_sire;
 h.add();
 sire=0;
 dam=0;
 sex=1;
 birth_year=.;
 output;
end;
if h.check(key:_dam) ne 0 then do;
 individual=_dam;
 h.add();
 sire=0;
 dam=0;
 sex=2;
 birth_year=.;
 output;
end;
drop _:;
run;

data key;
 set one;
 from=individual;to=sire;output;
 to=dam;output;
 keep from to;
run;


data full;
  set key 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;

%let individual=16;
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(where=(node=&amp;amp;individual))');
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;



data final_want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
end;
call missing(of _all_);
set want;
 individual=node;
 h.find();
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Oct 2016 05:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/302252#M312312</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-04T05:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/306917#M312313</link>
      <description>&lt;P&gt;Sorry for the delay..&lt;/P&gt;&lt;P&gt;it works perfectly!&lt;/P&gt;&lt;P&gt;thank you very much for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 18:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/306917#M312313</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-10-24T18:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/309919#M312314</link>
      <description>&lt;P&gt;hi Ksharp,&lt;BR /&gt;I need your help again!&lt;BR /&gt;For the last code, I can not combined several individuals (for looking) together into one table. That is, replace "% let individual = 16" with a table with several individuals.&lt;BR /&gt;how can I do it?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 01:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/309919#M312314</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-11-08T01:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/309927#M312315</link>
      <description>&lt;PRE&gt;
Sure.





data one;
input individual sire dam sex birth_year;
cards;
3 1 2 1 2005
10 3 4 2 2010
11 7 8 1 2011
13 11 10 1 2014
16 11 6 2 2015
20 17 18 2 2015
;
run;

data have;
 if _n_=1 then do;
  if 0 then set one;
  declare hash h(dataset:'one');
  h.definekey('individual');
  h.definedone();
 end;
set one;
output;
_sire=sire;
_dam=dam;
if h.check(key:_sire) ne 0 then do;
 individual=_sire;
 h.add();
 sire=0;
 dam=0;
 sex=1;
 birth_year=.;
 output;
end;
if h.check(key:_dam) ne 0 then do;
 individual=_dam;
 h.add();
 sire=0;
 dam=0;
 sex=2;
 birth_year=.;
 output;
end;
drop _:;
run;

data key;
 set one;
 from=individual;to=sire;output;
 to=dam;output;
 keep from to;
run;


data full;
  set key 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;
/*eplace "% let individual = 16" with a table with several individuals*/
data n;
 input node;
 cards;
 16
 20
 ;
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:'n');/***&amp;lt;---*******/
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;



data final_want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
end;
call missing(of _all_);
set want;
 individual=node;
 h.find();
run;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Nov 2016 03:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/309927#M312315</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-08T03:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311485#M312316</link>
      <description>&lt;P&gt;Hi Ksharp!&lt;/P&gt;&lt;P&gt;The code works, but sometimes (with some individuals in the data "n") the code gives error ( "ERROR: Key not found") in the final data set ( "final_want"). Why?&lt;BR /&gt;Reading the forum I found that this may be due to using "h.find ()" instead of "rc=h.find ()". what do you think?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 18:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311485#M312316</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-11-14T18:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311584#M312317</link>
      <description>&lt;P&gt;Yes. use "&lt;SPAN&gt;rc=h.find ()" &amp;nbsp;instead of "h.find()" .&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 02:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311584#M312317</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-15T02:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311652#M312318</link>
      <description>&lt;PRE&gt;Is it ok like this? &lt;BR /&gt;Is added something else?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;data final_want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h(dataset:'have');
  h.definekey('individual');
  h.definedata('sire','dam','sex','birth_year');
  h.definedone();
end;
call missing(of _all_);
set want;
 individual=node;
 &lt;SPAN&gt;rc=h.find()&lt;/SPAN&gt;;/***&amp;lt;---****/
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 11:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311652#M312318</guid>
      <dc:creator>alan_maxs</dc:creator>
      <dc:date>2016-11-15T11:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO SAS to build a pedigree of specific individuals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311895#M312319</link>
      <description>&lt;PRE&gt;
Yes. That is what I referred to .

&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2016 04:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-SAS-to-build-a-pedigree-of-specific-individuals/m-p/311895#M312319</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-16T04:26:08Z</dc:date>
    </item>
  </channel>
</rss>

