<?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: How to merge two datasets by two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652925#M196092</link>
    <description>&lt;DIV&gt;proc sort data=work.Data1;&lt;/DIV&gt;&lt;DIV&gt;by ICBSUC Jahr;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc summary data=Data1 nway;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; class &amp;nbsp;icbsuc Jahr;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var KehrwertM;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; output out=sum1 sum=sum1 n=n;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data Data2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; merge Data1 sum1 (in =in2);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; by icbsuc Jahr;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if in2;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;</description>
    <pubDate>Wed, 03 Jun 2020 16:10:30 GMT</pubDate>
    <dc:creator>smantha</dc:creator>
    <dc:date>2020-06-03T16:10:30Z</dc:date>
    <item>
      <title>How to merge two datasets by two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652869#M196079</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for taking your time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the dataset "Data1", with a structure like this:&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40315iC2B4034F566375D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2.PNG" alt="2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I have the Dataset "Sum1", which looks like this: &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="3.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40319i1036944393AB8903/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3.PNG" alt="3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to merge those two so that&amp;nbsp;for every row in data set "Data1" the corresponding values of variables sum1 and n from Dataset "Sum1" show up if the Jahr=Jahr and if ICBSUC=ICBSUC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for example for every observation in&amp;nbsp;data set "Data1" which in from Jahr 2010 and has an industry code ICBSUC of 10101010 the value in the variable sum1 should be 1.173... and the value in variable n should be 19.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my current code looks like this:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=work.Data1;&lt;/DIV&gt;&lt;DIV&gt;by ICBSUC;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc summary data=Data1 nway;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; class &amp;nbsp;icbsuc Jahr;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var KehrwertM;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; output out=sum1 sum=sum1 n=n;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data Data2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; merge Data1 sum1 (in =in2);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; by Jahr icbsuc;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if in2;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thank you for your help!&amp;nbsp;&lt;/DIV&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652869#M196079</guid>
      <dc:creator>tim-hahn</dc:creator>
      <dc:date>2020-06-03T13:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets by two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652877#M196081</link>
      <description>&lt;P&gt;I believe the code what you wrote is correct, a minor update to include if in1 and in2 as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Data2;
    merge Data1(in=in1) sum1 (in =in2);
    by Jahr icbsuc;
    if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652877#M196081</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-03T13:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets by two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652925#M196092</link>
      <description>&lt;DIV&gt;proc sort data=work.Data1;&lt;/DIV&gt;&lt;DIV&gt;by ICBSUC Jahr;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc summary data=Data1 nway;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; class &amp;nbsp;icbsuc Jahr;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var KehrwertM;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; output out=sum1 sum=sum1 n=n;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data Data2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; merge Data1 sum1 (in =in2);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; by icbsuc Jahr;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if in2;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Jun 2020 16:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-two-datasets-by-two-variables/m-p/652925#M196092</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-03T16:10:30Z</dc:date>
    </item>
  </channel>
</rss>

