<?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 Building Union/Merge Queries in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Building-Union-Merge-Queries/m-p/222#M54</link>
    <description>I have to datasets with two variables (ID, Value). Each observation in each table is unique. How to I get enterprise guide to build the union query to form one dataset with one variable (value). I want to end up with one dataset listing all unique value varibles.&lt;BR /&gt;
&lt;BR /&gt;
I know how to write a proc sql, but I want the gui to do it.&lt;BR /&gt;
&lt;BR /&gt;
Thank You&lt;BR /&gt;
Eric</description>
    <pubDate>Tue, 21 Mar 2006 21:14:52 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2006-03-21T21:14:52Z</dc:date>
    <item>
      <title>Building Union/Merge Queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Building-Union-Merge-Queries/m-p/222#M54</link>
      <description>I have to datasets with two variables (ID, Value). Each observation in each table is unique. How to I get enterprise guide to build the union query to form one dataset with one variable (value). I want to end up with one dataset listing all unique value varibles.&lt;BR /&gt;
&lt;BR /&gt;
I know how to write a proc sql, but I want the gui to do it.&lt;BR /&gt;
&lt;BR /&gt;
Thank You&lt;BR /&gt;
Eric</description>
      <pubDate>Tue, 21 Mar 2006 21:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Building-Union-Merge-Queries/m-p/222#M54</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-03-21T21:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Building Union/Merge Queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Building-Union-Merge-Queries/m-p/223#M55</link>
      <description>One way to do it is with a Full Outer Join keyed on the "value" column, with a calculated column as the output.&lt;BR /&gt;
&lt;BR /&gt;
For example, imagine these two data sets:&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
  do id=1 to 10;&lt;BR /&gt;
     value = ranuni(100);&lt;BR /&gt;
	 output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  do id=5 to 15;&lt;BR /&gt;
     value = ranuni(200);&lt;BR /&gt;
	 output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Join them in a query with a Full Outer Join on VALUE (not ID), specify that you want DISTINCT rows, and add this calculated column to the output:&lt;BR /&gt;
&lt;BR /&gt;
MAX(ONE.VALUE, TWO.VALUE)&lt;BR /&gt;
&lt;BR /&gt;
The resulting SQL is this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
 CREATE TABLE WORK.Query_for_TWO AS SELECT DISTINCT (MAX(TWO.value, ONE.value)) AS UniqueValue &lt;BR /&gt;
 FROM WORK.TWO AS TWO &lt;BR /&gt;
	  FULL JOIN WORK.ONE AS ONE ON (TWO.value = ONE.value);&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
If I've misunderstood what you're after, please follow up with another post.&lt;BR /&gt;
&lt;BR /&gt;
I know that I'm inviting comments from the peanut gallery about how this can be done in two lines of DATA step code; remember, the question was about how to get this done in the query UI &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Fri, 24 Mar 2006 21:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Building-Union-Merge-Queries/m-p/223#M55</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2006-03-24T21:45:18Z</dc:date>
    </item>
  </channel>
</rss>

