<?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: adding two dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145168#M38565</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table three as&lt;/P&gt;&lt;P&gt;select first.id,sum(first.a,second.a) as a&lt;/P&gt;&lt;P&gt;from first inner join second&lt;/P&gt;&lt;P&gt;on first.id=second.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Dec 2014 19:56:18 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-12-10T19:56:18Z</dc:date>
    <item>
      <title>adding two dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145166#M38563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P id="gt-src-tools"&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;Hello&lt;/SPAN&gt; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV id="gt-src-tools-l"&gt;&lt;DIV id="gt-input-tool"&gt;&lt;DIV id="itamenu"&gt;&lt;SPAN class="ita-kd-inputtools-div"&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class="almost_half_cell" id="gt-res-content"&gt;&lt;/P&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;How can I add&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;two&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;variables from two&lt;/SPAN&gt;&lt;SPAN class="hps"&gt; dataset&lt;/SPAN&gt;?&lt;BR /&gt; &lt;SPAN class="hps"&gt;As&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the picture&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;IMG alt="" class="jiveImage" src="https://communities.sas.com/legacyfs/online/8331_pastedImage_0.png" style="width: 554px; height: 209px;" /&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;I am currently using&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the rename&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;function&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;and join&lt;/SPAN&gt; dataset &lt;SPAN class="hps"&gt;in&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;one&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;and adds&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;variables&lt;/SPAN&gt;. &lt;SPAN class="hps"&gt;Seeking a&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;less&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;troublesome&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;solution.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN class="hps"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN class="hps"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN class="hps"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN class="hps"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;BR /&gt;&lt;P id="gt-src-tools"&gt;&lt;/P&gt;&lt;DIV id="gt-src-tools-l"&gt;&lt;DIV id="gt-input-tool"&gt;&lt;DIV id="itamenu"&gt;&lt;SPAN class="ita-kd-inputtools-div"&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class="almost_half_cell" id="gt-res-content"&gt;&lt;/P&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;I&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;have another question&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="hps"&gt;How to change&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;this command&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;to create a&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;dataset&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;with the result of&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the command.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN class="hps"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;BR /&gt;&lt;P&gt;&lt;A name="a001363172"&gt;from: &lt;/A&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001361224.htm" title="http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001361224.htm"&gt;http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001361224.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="[First or second table, but not both]" border="0" class="jiveImage" src="http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/images/query.gif" vspace="12" /&gt;&lt;/P&gt;&lt;P&gt;There is no keyword in PROC SQL that returns unique rows from the first and second table, but not rows that occur in both. Here is one way you can simulate this operation:&lt;/P&gt;&lt;PRE class="jive-pre"&gt;&lt;A name="a001363179"&gt;&lt;/A&gt;(query1 except query2) union (query2 except query1)&lt;/PRE&gt;&lt;P&gt;This example shows how to use this operation.&lt;/P&gt;&lt;PRE class="jive-pre"&gt;&lt;A name="a001363185"&gt;&lt;/A&gt;proc sql;&lt;/PRE&gt;&lt;PRE class="jive-pre"&gt; title 'A EXCLUSIVE UNION B';&lt;/PRE&gt;&lt;PRE class="jive-pre"&gt; (select * from sql.a except select * from sql.b)&lt;/PRE&gt;&lt;PRE class="jive-pre"&gt; union &lt;/PRE&gt;&lt;PRE class="jive-pre"&gt;(select * from sql.b except select * from sql.a);&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV dir="ltr"&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;Thank you&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;for your help.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Dec 2014 19:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145166#M38563</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2014-12-10T19:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: adding two dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145167#M38564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For the first part, if you're joining by id, then its pretty straightforward depending on which table (if any) would be the "master" table.&amp;nbsp; If neither, then you might consider:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; coalesce(t1,id, t2.id) as ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; coalesce(t1.a,0) + coalesce(t2.a,0) as a&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataset1 t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; full outer join dataset2 t2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on t1.id=t2.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you will have some issues if id is not unique in either table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the second part (without testing):&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select t1.* from (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select * from sql.a except select * from sql.b)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; union&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Select * from sql.b except select * from sql.a)&lt;/P&gt;&lt;P&gt;) t1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Dec 2014 19:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145167#M38564</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-12-10T19:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: adding two dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145168#M38565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table three as&lt;/P&gt;&lt;P&gt;select first.id,sum(first.a,second.a) as a&lt;/P&gt;&lt;P&gt;from first inner join second&lt;/P&gt;&lt;P&gt;on first.id=second.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Dec 2014 19:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-two-dataset/m-p/145168#M38565</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-12-10T19:56:18Z</dc:date>
    </item>
  </channel>
</rss>

