<?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: how to merge two datasets into one keeping all information available? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718119#M222175</link>
    <description>/********TYPO CORRECTED***********/&lt;BR /&gt;&lt;BR /&gt;DATA step merge wouldn't work if the key variable isn't unique, SQL procedure will:</description>
    <pubDate>Wed, 10 Feb 2021 04:52:21 GMT</pubDate>
    <dc:creator>qoit</dc:creator>
    <dc:date>2021-02-10T04:52:21Z</dc:date>
    <item>
      <title>how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718111#M222170</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
 infile datalines;
 input id year death reg;
 datalines;
1 2000 0 11
1 2001 0 12
1 2002 0 11
1 2003 0 11
3 2000 0 .
3 2001 0 11
3 2002 0 11
3 2003 0 11
5 2000 1 .
5 2001 1 .
5 2002 1 11
5 2003 1 11
;run;
proc print data=have1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
infile datalines;
input id year reg death sex inc;
datalines;
1 2000 11 0 1 1000
2 2000 12 0 1 2000
3 2000 13 0 2 3000
4 2000 12 0 1 4000
5 2000 13 1 2 3900
; run;&lt;BR /&gt;proc print data=have2;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines;
input id year death residence sex inc
1 2000 0 11 1 1000 
1 2001 0 12 1 1000 
1 2002 0 11 1 1000 
1 2003 0 11 1 1000 
2 2000 0 12 1 2000 
2 2001 0 . 1 2000
2 2002 0 . 1 2000
2 2003 0 . 1 2000
3 2000 0 13 2 3000
3 2001 0 11 2 3000
3 2002 0 11 2 3000
3 2003 0 11 2 3000
4 2000 0 12 1 4000
4 2001 0 . 1 4000
4 2002 0 . 1 4000
4 2003 0 . 1 4000
5 2000 1 13 2 3900
5 2001 1 . 2 3900
5 2002 1 11 2 3900
5 2003 1 11 2 3900
; 
run;
proc print data=want;&lt;BR /&gt;run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'd like to merge have1 and have 2&amp;nbsp; datasets into a file that looks like want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance.&lt;/P&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718111#M222170</guid>
      <dc:creator>Lily07</dc:creator>
      <dc:date>2021-02-10T12:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718112#M222171</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
 input id year death reg;
 datalines;
1 2000 0 11
1 2001 0 12
1 2002 0 11
1 2003 0 11
3 2000 0 . 
3 2001 0 11
3 2002 0 11
3 2003 0 11
5 2000 1 . 
5 2001 1 . 
5 2002 1 11
5 2003 1 11
;

data have2;
infile datalines;
input id year reg death sex inc;
datalines;
1 2000 11 0 1 1000
2 2000 12 0 1 2000
3 2000 13 0 2 3000
4 2000 12 0 1 4000
5 2000 13 1 2 3900
;

data want;
   merge have1 have2;
   by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 04:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718112#M222171</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T04:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718118#M222174</link>
      <description>&lt;P&gt;DATA step merge would work if the key variable isn't unique, SQL procedure will:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
	infile datalines;
	input id year death reg;
	datalines;
1 2000 0 11
1 2001 0 12
1 2002 0 11
1 2003 0 11
3 2000 0 .
3 2001 0 11
3 2002 0 11
3 2003 0 11
5 2000 1 .
5 2001 1 .
5 2002 1 11
5 2003 1 11
;
run;

data have2;
	infile datalines;
	input id year reg death sex inc;
	datalines;
1 2000 11 0 1 1000
2 2000 12 0 1 2000
3 2000 13 0 2 3000
4 2000 12 0 1 4000
5 2000 13 1 2 3900
;
run;

proc sql;
	create table want as
		select distinct coalesce(have1.id,have2.id) as id,coalesce(have1.year,have2.year) as year,coalesce(have1.death,have2.death) as death,have1.reg,have2.sex,have2.inc
			from have1 full join have2 on have1.id = have2.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 04:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718118#M222174</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-10T04:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718119#M222175</link>
      <description>/********TYPO CORRECTED***********/&lt;BR /&gt;&lt;BR /&gt;DATA step merge wouldn't work if the key variable isn't unique, SQL procedure will:</description>
      <pubDate>Wed, 10 Feb 2021 04:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718119#M222175</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-10T04:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718126#M222178</link>
      <description>&lt;P&gt;Please explain the logic!&lt;/P&gt;
&lt;P&gt;It seems that you want each id four times in "want". What should happen, if more than four obs exist for one id in "have1"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: You need to check the code you have posted, there is an error in the step creating "have1": Five variables in the input statement, but only four in the datalines.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 05:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718126#M222178</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-10T05:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718128#M222179</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;agree. I should have pointed that out. I think the data should be as in my snippet&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 06:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718128#M222179</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T06:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to merge two datasets into one keeping all information available?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718219#M222232</link>
      <description>&lt;P&gt;Thanks for your question.&lt;/P&gt;&lt;P&gt;It's not the case that I have more than 4 obs in have 1 since I made sure that there are no more than four obs. (I eliminated years out of the range).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create all the four years (four rows) for each id in have 2. Also, unless there is information in death and residence in have 1, I want to use information for deaths, sex, and inc, but not residence.&lt;/P&gt;&lt;P&gt;I hope that my explanation helps to figure out the logic. Please let me know if it's still unclear.&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="ms-editor-squiggler"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-two-datasets-into-one-keeping-all-information/m-p/718219#M222232</guid>
      <dc:creator>Lily07</dc:creator>
      <dc:date>2021-02-10T12:48:56Z</dc:date>
    </item>
  </channel>
</rss>

