<?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: Output both observations in a merge if they match in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732460#M228239</link>
    <description>Yep!</description>
    <pubDate>Fri, 09 Apr 2021 10:53:13 GMT</pubDate>
    <dc:creator>Feefee</dc:creator>
    <dc:date>2021-04-09T10:53:13Z</dc:date>
    <item>
      <title>Output both observations in a merge if they match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732458#M228237</link>
      <description>&lt;P&gt;Hi Guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick question on merging and joining datasets:&lt;/P&gt;&lt;P&gt;If I have two datasets and if they both have a matching obs (by a certain key), how can i output both observations from each dataset into my output dataset please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 10:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732458#M228237</guid>
      <dc:creator>Feefee</dc:creator>
      <dc:date>2021-04-09T10:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Output both observations in a merge if they match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732459#M228238</link>
      <description>&lt;P&gt;Do those datasets have the same structure (same variables)?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 10:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732459#M228238</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-09T10:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Output both observations in a merge if they match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732460#M228239</link>
      <description>Yep!</description>
      <pubDate>Fri, 09 Apr 2021 10:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732460#M228239</guid>
      <dc:creator>Feefee</dc:creator>
      <dc:date>2021-04-09T10:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Output both observations in a merge if they match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732465#M228240</link>
      <description>&lt;P&gt;See these simple example tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input x y;
datalines;
1 2
2 3
3 4
;

data b;
input x y;
datalines;
1 3
2 4
4 6
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can either merge them and use a RENAME= option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
merge
  a (in=a)
  b (in=b rename=(y=_y))
;
by x;
if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can stack them:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
set
  a (in=a)
  b (in=b)
;
by x;
if first.x ne last.x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Mind that this works only if there's maximally 1 observation for a key in each dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 11:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-observations-in-a-merge-if-they-match/m-p/732465#M228240</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-09T11:05:37Z</dc:date>
    </item>
  </channel>
</rss>

