<?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: Create a family tree by join data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809517#M319241</link>
    <description>&lt;P&gt;It's not exactly a family &lt;EM&gt;&lt;STRONG&gt;tree&lt;/STRONG&gt;&lt;/EM&gt;, is it?&amp;nbsp; It appears you only need to prepare for two generations.&amp;nbsp; Is that correct?&lt;/P&gt;</description>
    <pubDate>Sun, 24 Apr 2022 17:55:15 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-04-24T17:55:15Z</dc:date>
    <item>
      <title>Create a family tree by join data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809514#M319239</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table where the relation between two is known.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_1-1650818449374.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70765i6C69040A85018B56/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_1-1650818449374.png" alt="sarahzhou_1-1650818449374.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a table for a couple related to their child records, for example:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_0-1650818060796.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70764i5AE3AAFA45A51CA0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_0-1650818060796.png" alt="sarahzhou_0-1650818060796.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried to duplicate the table then left join the id1's and id2's, however I couldn't get the correct result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code show as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rf;
input p1$ p2$ rlf$;
cards;
f123 s234 son
s234 f123 father
m345 s234 son
s234 m345 mother
f123 m345 wife
m345 f123 husband
;

data rb;
input p1$ p2$ rlb$;
cards;
f123 s234 son
s234 f123 father
m345 s234 son
s234 m345 mother
f123 m345 wife
m345 f123 husband
;

proc sql;
select rf.p1 as id1, rf.rlf as name1, 
       rb.p2 as id2, rb.rlb as name2, 
       rb.p1 as id3, rb.rlb as name3 
from rf left join rb
on rf.p2=rb.p1
where (rlf in ("father", "mother") and rlb in ("son","daughter"));
quit;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;I get the wrong result:&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_3-1650819388151.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70767i3616B2F282867B55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_3-1650819388151.png" alt="sarahzhou_3-1650819388151.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I get the &lt;STRONG&gt;&lt;U&gt;correct result&lt;/U&gt; &lt;/STRONG&gt;as this?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_4-1650819460008.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70768i53E5AE49CD3753EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_4-1650819460008.png" alt="sarahzhou_4-1650819460008.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly advise&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2022 16:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809514#M319239</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-04-24T16:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a family tree by join data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809517#M319241</link>
      <description>&lt;P&gt;It's not exactly a family &lt;EM&gt;&lt;STRONG&gt;tree&lt;/STRONG&gt;&lt;/EM&gt;, is it?&amp;nbsp; It appears you only need to prepare for two generations.&amp;nbsp; Is that correct?&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2022 17:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809517#M319241</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-24T17:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a family tree by join data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809527#M319247</link>
      <description>&lt;P&gt;Why do you need duplicate results? Wouldn't this be more useful :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rf;
input p1$ p2$ rlf$;
cards;
f123 s234 son
s234 f123 father
m345 s234 son
s234 m345 mother
f123 m345 wife
m345 f123 husband
;

proc sql;
/* create table cmf as */
select unique
    a.p2 as child,
    b.p2 as mother,
    c.p2 as father
from 
    rf as a left join
    rf as b on a.p2 = b.p1 left join
    rf as c on a.p2 = c.p1
where a.rlf in ("son","daughter") and b.rlf = "mother" and c.rlf = "father";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1650828473336.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70769i6732E5EA21F1A596/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1650828473336.png" alt="PGStats_0-1650828473336.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Or maybe :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/* create table cmf as */
select unique
    a.p2 as child,
    a.rlf as rlf,
    b.p2 as mother,
    c.p2 as father
from 
    rf as a left join
    rf as b on a.p2 = b.p1 left join
    rf as c on a.p2 = c.p1
where a.rlf in ("son","daughter") and b.rlf = "mother" and c.rlf = "father";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_1-1650828626506.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70770i78CA8990B54B2BD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_1-1650828626506.png" alt="PGStats_1-1650828626506.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2022 19:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809527#M319247</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-04-24T19:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a family tree by join data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809529#M319249</link>
      <description>&lt;P&gt;But you could also simply transpose your actual data :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=rf; by p1 rlf; run;

proc transpose data=rf out=cmf(drop=_name_);
where rlf in ("mother", "father", "uncle", "aunt");
by p1;
id rlf;
var p2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Apr 2022 19:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809529#M319249</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-04-24T19:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a family tree by join data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809697#M319307</link>
      <description>&lt;P&gt;yes, only two generations. thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 13:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-family-tree-by-join-data-sets/m-p/809697#M319307</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-04-25T13:51:10Z</dc:date>
    </item>
  </channel>
</rss>

