<?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: Merge Problems in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391612#M94104</link>
    <description>&lt;P&gt;So if B has 581 observations and 34 do not match any ids from A that leaves 547 that do match. The count of 551 matched records means that four extra observations were added by merging with A. &amp;nbsp;So either one id in B matched to 5 observations in A or some other combination. &amp;nbsp;To find which ids are appearing in multiple times you can use the FIRST. and LAST. variables that the BY statement will generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
  merge alldata (in=in1) pubdata3 (in=in2);
  by course;
  if in1 and in2 and not (first.course and last.course);
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Aug 2017 18:00:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-08-29T18:00:11Z</dc:date>
    <item>
      <title>Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391512#M94031</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm merging two datasets alldata and pubdata. &amp;nbsp;alldata has 589 observations and pubdata has 581.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following code returns 34 observations:&lt;/P&gt;&lt;P&gt;data whyin;&lt;BR /&gt;merge alldata (in=a) pubdata2 (in=b);&lt;BR /&gt;by course;&lt;BR /&gt;if b and not a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following code returns 551 observations:&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;merge alldata (in=a) pubdata2 (in=b);&lt;BR /&gt;by course;&lt;BR /&gt;if b and a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shouldn't those two be adding up to 581 and not 585?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;p.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391512#M94031</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T15:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391515#M94034</link>
      <description>How many records do you get without any IF statement?</description>
      <pubDate>Tue, 29 Aug 2017 15:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391515#M94034</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T15:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391521#M94036</link>
      <description>&lt;P&gt;data test;&lt;BR /&gt;merge alldata (in=a) pubdata2 (in=b);&lt;BR /&gt;by course;&lt;BR /&gt;/** if b and a;**/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this gives me 623 observations.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391521#M94036</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T15:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391523#M94037</link>
      <description>&lt;P&gt;There are 3 possibilities:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A and B&lt;/P&gt;
&lt;P&gt;A and not B&lt;/P&gt;
&lt;P&gt;not A and B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the first is common to both &amp;nbsp;A and B.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391523#M94037</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-08-29T15:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391524#M94038</link>
      <description>&lt;P&gt;So your data isn't one to one. If the data was one to one - means you have a single unique record for every course then what you expect would be true. But becuase you're likely doing a one to many or possibly many to many you don't get the results you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you edit your response? I could have sworn I initially read a number less than either of your totals....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, you need to determine if your data is one to one or many to one and how you should merge it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391524#M94038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T15:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391525#M94039</link>
      <description>&lt;P&gt;sorry yes - i ran the wrong code without the if statement. &amp;nbsp;Thought i edited if before anyone read it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391525#M94039</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T15:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391526#M94040</link>
      <description>&lt;P&gt;The issue that makes this more complex:&amp;nbsp; ALLDATA may contain multiple observations for the same COURSE.&amp;nbsp; Thus if a course exists in PUBDATA, there is no telling how many observations it will match in ALLDATA.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391526#M94040</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-29T15:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391527#M94041</link>
      <description>&lt;P&gt;Here's a quick example on how to test for something like this using the flags. Then you can filter your data and see what's happening for each set of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

data class2;
set sashelp.class;
if age=12 then delete;
bmi = weight**2/height*2;
keep name bmi;
run;

proc sort data=class;
by name;
proc sort data=class2;
by name;
run;

data want;
merge class (in=a) class2(in=b);
by name;
if a and not b then flag=1;
else if a and b then flag=2;
else flag=3;

run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391527#M94041</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T15:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391528#M94042</link>
      <description>&lt;P&gt;Will try both those solutions and revert but I have used the following code to ensure I have just one obs for each course. &amp;nbsp;Would it not get rid of duplicates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data allcourses;&lt;BR /&gt;set new14;&lt;BR /&gt;by course;&lt;BR /&gt;if first.course;&lt;BR /&gt;drop military nonmilitary total;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391528#M94042</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T15:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391529#M94043</link>
      <description>Yes it will, but are both of your data sets de-duplicated?</description>
      <pubDate>Tue, 29 Aug 2017 15:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391529#M94043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T15:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391535#M94047</link>
      <description>&lt;P&gt;Yes, both deduped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;merge alldata (in=a) pubdata3 (in=b);&lt;BR /&gt;by course;&lt;BR /&gt;if a and not b then flag=1;&lt;BR /&gt;else if a and b then flag=2;&lt;BR /&gt;else flag=3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;623 observations in total&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flag =1 - 38 observations&lt;/P&gt;&lt;P&gt;flag =2 - &amp;nbsp;551 observations&lt;/P&gt;&lt;P&gt;flag=3 - &amp;nbsp; 34 observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same as with if statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only thing I can think of is that in one of the datasets I had to manipulate the data to get the by variable (course) in the right format. &amp;nbsp;In my first run through I got the 'by variables of multilple length...' message. &amp;nbsp;I fixed it (I think) and don't get the error message. &amp;nbsp;But when I run proc contents, this is how the variables are displayed... could this be the problem?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alldata.PNG" style="width: 419px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14704i6437434427677D0A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alldata.PNG" alt="alldata.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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pubdata.PNG" style="width: 556px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14705i6CEF8E925B614546/image-size/large?v=v2&amp;amp;px=999" role="button" title="pubdata.PNG" alt="pubdata.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391535#M94047</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T15:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391538#M94050</link>
      <description>&lt;P&gt;Look at the 34 records. You should be able to figure out the issue by examing your data. Look to see if the course values are what you expect or if you have multiple cases for example, ie "Math" is not equal to "math'.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391538#M94050</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T15:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391573#M94075</link>
      <description>&lt;P&gt;So you have 623 total ids. Of those 551 are in both A and B and 38 are in A only and the final 34 are in B only.&lt;/P&gt;
&lt;P&gt;What is the question at this point?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 16:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391573#M94075</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-29T16:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391592#M94089</link>
      <description>&lt;P&gt;A&amp;amp;B - 551&lt;/P&gt;&lt;P&gt;B only - 34&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;= 585 in B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset B only has 581 observations to begin with.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 17:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391592#M94089</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T17:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391596#M94092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156259"&gt;@piyushas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;A&amp;amp;B - 551&lt;/P&gt;
&lt;P&gt;B only - 34&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;= 585 in B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset B only has 581 observations to begin with.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The merged result can be larger than the original data set because it now includes records from A that were not in B to start with. If you don't want that, then you can use the IN to filter your results.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 17:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391596#M94092</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-29T17:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391612#M94104</link>
      <description>&lt;P&gt;So if B has 581 observations and 34 do not match any ids from A that leaves 547 that do match. The count of 551 matched records means that four extra observations were added by merging with A. &amp;nbsp;So either one id in B matched to 5 observations in A or some other combination. &amp;nbsp;To find which ids are appearing in multiple times you can use the FIRST. and LAST. variables that the BY statement will generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
  merge alldata (in=in1) pubdata3 (in=in2);
  by course;
  if in1 and in2 and not (first.course and last.course);
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 18:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391612#M94104</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-29T18:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391668#M94130</link>
      <description>&lt;P&gt;OMG thank you! Yup that's it. &amp;nbsp;I introduced duplicates further down in my code, after doing my check for duplicates, and did not catch it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been mucking with this for days -thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 20:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/391668#M94130</guid>
      <dc:creator>piyushas</dc:creator>
      <dc:date>2017-08-29T20:24:28Z</dc:date>
    </item>
  </channel>
</rss>

