<?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: Data Step Merge Results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353467#M82513</link>
    <description>&lt;P&gt;Good solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you&amp;nbsp;have at most one observation per MEMBER in each data set, you could get the new result with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set dummy dummy2;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.id=0 or last.id=0 then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there's a possibility of a many-to-one match (or worse yet, many-to-many) it gets more complex.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2017 21:17:30 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-04-25T21:17:30Z</dc:date>
    <item>
      <title>Data Step Merge Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353453#M82509</link>
      <description>&lt;P&gt;Here is&amp;nbsp;my test data and program:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
  infile datalines;
  length ID 4 Member $9.;
  input ID Member $9.;
  cards;
6666 Ben
3333 Christine
9999 Kelly
1111 Nick
5555 Josh
;;;;
run;

data dummy2;
  infile datalines;
  length ID 4 Member $9.;
  input ID Member $9.;
  cards;
3333 Jim
6666 Mike
1111 Luke
2222 Brian
5555 Jesus
;;;;
run;
   
proc sort data=dummy;
  by ID;
run;

proc sort data=dummy2;
  by ID;
run;

data test;
  merge dummy(in=a) dummy2(in=b);
  by ID;
  if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The test dataset only has observations from dummy2. Why is this? I want all observations from each where ID matches (I'm purposely trying to avoid PROC SQL).&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 20:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353453#M82509</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-04-25T20:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step Merge Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353456#M82510</link>
      <description>&lt;P&gt;Your final data set can only contain one variable named MEMBER?&amp;nbsp; But you have conflicting values coming from both data sets.&amp;nbsp; When you get MEMBER from the first data set, what would you like its variable name to be after the MERGE?&amp;nbsp; When you get MEMBER from the second data set, what would you like its variable name to be after the MERGE?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 20:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353456#M82510</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-25T20:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step Merge Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353463#M82512</link>
      <description>&lt;P&gt;Renaming like this essentially solves the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  merge dummy(in=a) dummy2(in=b rename=(Member=Memberr));
  by ID;
  if a and b then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what if I want to display it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1111 Nick
1111 Luke
3333 Christine
3333 Jim
6666 Ben
6666 Mike
5555 Josh
5555 Jesus

or 

1111 Luke
1111 Nick
3333 Jim
3333 Christine
6666 Mike
6666 Ben
5555 Jesus
5555 Josh&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Apr 2017 21:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353463#M82512</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-04-25T21:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step Merge Results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353467#M82513</link>
      <description>&lt;P&gt;Good solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you&amp;nbsp;have at most one observation per MEMBER in each data set, you could get the new result with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set dummy dummy2;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.id=0 or last.id=0 then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there's a possibility of a many-to-one match (or worse yet, many-to-many) it gets more complex.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 21:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step-Merge-Results/m-p/353467#M82513</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-25T21:17:30Z</dc:date>
    </item>
  </channel>
</rss>

