<?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: Need help with merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164315#M263591</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One scenario is there are more group value in B than in A.&lt;/P&gt;&lt;P&gt;For example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data a;
group=1;v=2; output;
group=2;v=2; output;
run;
data b;
group=1;w=2; output;
group=2;w=2; output;
group=2;w=2; output;
run;

data ab;
merge A (in=a) B (in=b);
by group;
if a ;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you strictly request the same number of obs with A , use this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data ab;
a=0;
merge A (in=a) B (in=b);
by group;
if a ;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Aug 2014 12:03:54 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-08-17T12:03:54Z</dc:date>
    <item>
      <title>Need help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164314#M263590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I am merging 2 datasets- A and B with 247 and 18 observations respectively as below , I am getting 248 observations in the dataset AB. Is this correct?&lt;/P&gt;&lt;P&gt;As much as I know, the no.of observations in the new dataset AB should be 247. Need help in solving this problem. Appreciate it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data AB AB_dummy;&lt;/P&gt;&lt;P&gt;length common_variable $ 50;&lt;/P&gt;&lt;P&gt;merge A (in=a) B (in=b);&lt;/P&gt;&lt;P&gt;by common_variable;&lt;/P&gt;&lt;P&gt;if a then output AB;&lt;/P&gt;&lt;P&gt;if a and not b then output AB_dummy;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Aug 2014 09:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164314#M263590</guid>
      <dc:creator>pavan_reddy</dc:creator>
      <dc:date>2014-08-17T09:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164315#M263591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One scenario is there are more group value in B than in A.&lt;/P&gt;&lt;P&gt;For example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data a;
group=1;v=2; output;
group=2;v=2; output;
run;
data b;
group=1;w=2; output;
group=2;w=2; output;
group=2;w=2; output;
run;

data ab;
merge A (in=a) B (in=b);
by group;
if a ;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you strictly request the same number of obs with A , use this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data ab;
a=0;
merge A (in=a) B (in=b);
by group;
if a ;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Aug 2014 12:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164315#M263591</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-17T12:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164316#M263592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your questions can be rephrased as how can there be MORE observations output to AB than read from A when you only output to AB when the record was in A?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This can occur on a merge when one of the other datasets in the merge has more observations for the same by group.&lt;/P&gt;&lt;P&gt;Consider a simple example.&amp;nbsp; If A has 4 observations with GROUP values of (1 2 3 4) and B has 3 observations when GROUP values of (1 1 2 ) then your program will generate 5 observations to AB because GROUP 1 will have two observations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Aug 2014 16:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164316#M263592</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-17T16:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164317#M263593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot Xia, this helped me a lot&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Aug 2014 17:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-merge/m-p/164317#M263593</guid>
      <dc:creator>pavan_reddy</dc:creator>
      <dc:date>2014-08-17T17:17:06Z</dc:date>
    </item>
  </channel>
</rss>

