<?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: Merging data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837961#M331339</link>
    <description>&lt;P&gt;It seems that the rows match one to one and you don't need to merge by key.&lt;/P&gt;
&lt;P&gt;If that's not the case, provide a different sample.&lt;/P&gt;
&lt;P&gt;Otherwise simply run:&lt;/P&gt;
&lt;P&gt;data WANT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;merge DAD KIDS;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Oct 2022 23:29:09 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2022-10-11T23:29:09Z</dc:date>
    <item>
      <title>Merging data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837956#M331335</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have two data set I will like to merge. Data one have two ID i will like to use to merge but only one of the ID is in Data two. I would like to merge data two to Data one. I have provided a sample data and what my expected output should be. I use proc sql one-many merge but i did not get the expected result.&lt;/P&gt;&lt;P&gt;/*Data one*/&lt;/P&gt;&lt;P&gt;data dads;&lt;BR /&gt;input fid obs name $ inc ;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 Art 21000&lt;BR /&gt;1 3 Art 22000&lt;BR /&gt;1 4 Art 23000&lt;BR /&gt;2 5 Bill 30000&lt;BR /&gt;2 6 Bill 30000&lt;BR /&gt;2 7 Bill 31000&lt;BR /&gt;3 2 Paul 25000&lt;BR /&gt;3 5 Paul 25000&lt;BR /&gt;3 4 Paul 25000&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data kids;&lt;BR /&gt;input famid kidname $ birth age wt yr ;&lt;BR /&gt;cards;&lt;BR /&gt;1 Beth 1 9 60 2007&lt;BR /&gt;1 Bob 2 6 40 2008&lt;BR /&gt;1 Barb 3 3 20 2009&lt;BR /&gt;2 Andy 1 8 80 2007&lt;BR /&gt;2 Al 2 6 50 2008&lt;BR /&gt;2 Ann 3 2 20 2009&lt;BR /&gt;3 Pete 1 6 60 2007&lt;BR /&gt;3 Pam 2 4 40 2008&lt;BR /&gt;3 Phil 3 2 20 2009&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*Expected output*/&lt;/P&gt;&lt;P&gt;fid obs name $ inc famid kidname $ birth age wt sex $&lt;BR /&gt;1 2 Art 21000 1 Beth 1 9 60 2007&lt;BR /&gt;1 3 Art 22000 1 Bob 2 6 40 2008&lt;BR /&gt;1 4 Art 23000 1 Barb 3 3 20 2009&lt;BR /&gt;2 5 Bill 30000 2 Andy 1 8 80 2007&lt;BR /&gt;2 6 Bill 30000 2 Al 2 6 50 2008&lt;BR /&gt;2 7 Bill 31000 2 Ann 3 2 20 2009&lt;BR /&gt;3 2 Paul 25000 3 Pete 1 6 60 2007&lt;BR /&gt;3 5 Paul 25000 3 Pam 2 4 40 2008&lt;BR /&gt;3 4 Paul 25000 3 Phil 3 2 20 2009&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Sample code*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table dadkid2 as&lt;BR /&gt;select *&lt;BR /&gt;from dads, kids&lt;BR /&gt;where dads.fid=kids.famid&lt;BR /&gt;order by dads.fid, kids.kidname;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 23:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837956#M331335</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2022-10-11T23:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837961#M331339</link>
      <description>&lt;P&gt;It seems that the rows match one to one and you don't need to merge by key.&lt;/P&gt;
&lt;P&gt;If that's not the case, provide a different sample.&lt;/P&gt;
&lt;P&gt;Otherwise simply run:&lt;/P&gt;
&lt;P&gt;data WANT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;merge DAD KIDS;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 23:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837961#M331339</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-10-11T23:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837978#M331345</link>
      <description>&lt;P&gt;The "DADS" dataset seems messed up.&amp;nbsp; What family has three dads?&amp;nbsp; And if they did what are the odds that they are all named ART?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you reduce the DADS dataset to one observation per family then a simple data step merge will work.&amp;nbsp; You will need to make sure the two versions of the family id are using the same variable name however.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dads;
  input fid obs name $ inc ;
cards;
1 2 Art 21000
1 3 Art 22000
1 4 Art 23000
2 5 Bill 30000
2 6 Bill 30000
2 7 Bill 31000
3 2 Paul 25000
3 5 Paul 25000
3 4 Paul 25000
;

data kids;
  input famid kidname $ birth age wt yr ;
cards;
1 Beth 1 9 60 2007
1 Bob 2 6 40 2008
1 Barb 3 3 20 2009
2 Andy 1 8 80 2007
2 Al 2 6 50 2008
2 Ann 3 2 20 2009
3 Pete 1 6 60 2007
3 Pam 2 4 40 2008
3 Phil 3 2 20 2009
;

proc summary data=dads(rename=(fid=famid)) nway;
  by famid name ;
  var inc;
  output out=one_dad(drop=_type_ _freq_) max=;
run;

data want;
  merge one_dad kids;
  by famid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    famid    name     inc     kidname    birth    age    wt     yr

 1       1      Art     23000     Beth        1       9     60    2007
 2       1      Art     23000     Bob         2       6     40    2008
 3       1      Art     23000     Barb        3       3     20    2009
 4       2      Bill    31000     Andy        1       8     80    2007
 5       2      Bill    31000     Al          2       6     50    2008
 6       2      Bill    31000     Ann         3       2     20    2009
 7       3      Paul    25000     Pete        1       6     60    2007
 8       3      Paul    25000     Pam         2       4     40    2008
 9       3      Paul    25000     Phil        3       2     20    2009
&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Oct 2022 03:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data/m-p/837978#M331345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-12T03:23:49Z</dc:date>
    </item>
  </channel>
</rss>

