<?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 datasets with unequal observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557675#M155507</link>
    <description>&lt;P&gt;Still not posted using "Insert SAS code".&amp;nbsp; When I cut-and-paste your code into SAS I don't get the correct results, I get missing rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2019 02:38:22 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2019-05-10T02:38:22Z</dc:date>
    <item>
      <title>Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557658#M155489</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I acme across a very basic problem with merging dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datsets where one data frame has more observations than other and the by variable value for non matched observation is also different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&amp;nbsp; _1;&lt;/P&gt;&lt;P&gt;input subject $ marks;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Physics 24&lt;/P&gt;&lt;P&gt;Chem 34&lt;/P&gt;&lt;P&gt;Maths 87&lt;/P&gt;&lt;P&gt;Biology 64&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _2;&lt;/P&gt;&lt;P&gt;input subject $ name $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Physics Maria&lt;/P&gt;&lt;P&gt;Chem John&lt;/P&gt;&lt;P&gt;Biology Jane;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data merg;&lt;/P&gt;&lt;P&gt;merge _2 _1;&lt;/P&gt;&lt;P&gt;by subject;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I am encountering is because a merge statement is an executable statement it automatically retains the value of previous observation after the first iteration and does not set it to missing which is why for Maths also the name is coming as Jane because it is not allowing a missing value here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Subject Name Marks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Physics Maria 24&lt;/P&gt;&lt;P&gt;Chem&amp;nbsp; John 34&lt;/P&gt;&lt;P&gt;Maths&amp;nbsp; Jane 87&lt;/P&gt;&lt;P&gt;Biology Jane 64&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;Subject Name Marks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Physics Maria 24&lt;/P&gt;&lt;P&gt;Chem&amp;nbsp; John 34&lt;/P&gt;&lt;P&gt;Maths . 87&lt;/P&gt;&lt;P&gt;Biology Jane 64&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To put the question in one line, How to get all observations from one dataset when merging even if the by variable does not have the same values in two dataset for some observations?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 00:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557658#M155489</guid>
      <dc:creator>anshul_900</dc:creator>
      <dc:date>2019-05-10T00:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557660#M155491</link>
      <description>&lt;P&gt;Edit your post using "Insert SAS Code", so I can cut-and-paste it into SAS.&amp;nbsp; Don't make us do your work in creating syntactically correct code.&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 01:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557660#M155491</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-10T01:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557666#M155495</link>
      <description>&lt;P&gt;Your code throws an ERROR because the datasets are not properly sorted.&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 01:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557666#M155495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-10T01:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557670#M155498</link>
      <description>&lt;P&gt;Sorry about that!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _1;&lt;/P&gt;&lt;P&gt;input id subject $ marks;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;101 Physics 24&lt;/P&gt;&lt;P&gt;101 Chem 34&lt;/P&gt;&lt;P&gt;101 Maths 87&lt;/P&gt;&lt;P&gt;101 Biology 64&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _2;&lt;/P&gt;&lt;P&gt;input id subject $ name $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;101 Physics Maria&lt;/P&gt;&lt;P&gt;101 Chem John&lt;BR /&gt;101 Biology Jane&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= _1;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _3;&lt;BR /&gt;merge _1 _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current output&lt;/P&gt;&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;&lt;P&gt;101 Chem 34 John&lt;/P&gt;&lt;P&gt;101 Biology 87 Jane&lt;/P&gt;&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;&lt;P&gt;101 Chem 34 John&lt;/P&gt;&lt;P&gt;101 Maths 87&amp;nbsp; .&lt;/P&gt;&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 02:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557670#M155498</guid>
      <dc:creator>anshul_900</dc:creator>
      <dc:date>2019-05-10T02:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557671#M155499</link>
      <description>&lt;P&gt;rephrasing the question again and copying the code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _1;&lt;/P&gt;&lt;P&gt;input id subject $ marks;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;101 Physics 24&lt;/P&gt;&lt;P&gt;101 Chem 34&lt;/P&gt;&lt;P&gt;101 Maths 87&lt;/P&gt;&lt;P&gt;101 Biology 64&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _2;&lt;/P&gt;&lt;P&gt;input id subject $ name $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;101 Physics Maria&lt;/P&gt;&lt;P&gt;101 Chem John&lt;BR /&gt;101 Biology Jane&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= _1;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data= _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _3;&lt;BR /&gt;merge _1 _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current output&lt;/P&gt;&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;&lt;P&gt;101 Chem 34 John&lt;/P&gt;&lt;P&gt;101 Biology 87 Jane&lt;/P&gt;&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;&lt;P&gt;101 Chem 34 John&lt;/P&gt;&lt;P&gt;101 Maths 87&amp;nbsp; .&lt;/P&gt;&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 02:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557671#M155499</guid>
      <dc:creator>anshul_900</dc:creator>
      <dc:date>2019-05-10T02:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557672#M155505</link>
      <description>&lt;P&gt;You need to merge by ID and SUBJECT. Replace your BY statements with 'BY ID SUBJECT' and you should get your expected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191837"&gt;@anshul_900&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;rephrasing the question again and copying the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _1;&lt;/P&gt;
&lt;P&gt;input id subject $ marks;&lt;/P&gt;
&lt;P&gt;datalines;&lt;BR /&gt;101 Physics 24&lt;/P&gt;
&lt;P&gt;101 Chem 34&lt;/P&gt;
&lt;P&gt;101 Maths 87&lt;/P&gt;
&lt;P&gt;101 Biology 64&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _2;&lt;/P&gt;
&lt;P&gt;input id subject $ name $;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;101 Physics Maria&lt;/P&gt;
&lt;P&gt;101 Chem John&lt;BR /&gt;101 Biology Jane&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data= _1;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data= _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data _3;&lt;BR /&gt;merge _1 _2;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current output&lt;/P&gt;
&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;
&lt;P&gt;101 Chem 34 John&lt;/P&gt;
&lt;P&gt;101 Biology 87 Jane&lt;/P&gt;
&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected output&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;101 Physics 24 Maria&lt;/P&gt;
&lt;P&gt;101 Chem 34 John&lt;/P&gt;
&lt;P&gt;101 Maths 87&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;101 Biology 64 Jane&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 02:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557672#M155505</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-10T02:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557675#M155507</link>
      <description>&lt;P&gt;Still not posted using "Insert SAS code".&amp;nbsp; When I cut-and-paste your code into SAS I don't get the correct results, I get missing rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 02:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/557675#M155507</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-10T02:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with unequal observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/558567#M155903</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _1;
input id subject $ marks;
datalines;
101 Physics 24
101 Chem 34
101 Maths 87
101 Biology 64
;
run;

data _2;
input id subject $ name $;
datalines;
101 Physics Maria
101 Chem John
101 Biology Jane
;
run;

proc sort data= _1;
by id subject;
run;

proc sort data= _2;
by id subject;
run;

data _3;
merge _1 _2;
by id subject;
run;

proc print data=_3 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; id    subject    marks    name

101    Biology      64     Jane 
101    Chem         34     John 
101    Maths        87          
101    Physics      24     Maria
&lt;/PRE&gt;
&lt;P&gt;Please take note of the proper methods for posting code, textual data and "listing" results, and the fact that missing character values are not&amp;nbsp;displayed as dots.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 09:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-unequal-observations/m-p/558567#M155903</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-14T09:05:46Z</dc:date>
    </item>
  </channel>
</rss>

