<?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: proc sql question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27345#M6239</link>
    <description>Hi.&lt;BR /&gt;
How about this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data main;&lt;BR /&gt;
input key;&lt;BR /&gt;
cards;&lt;BR /&gt;
1&lt;BR /&gt;
2&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data minor;&lt;BR /&gt;
input _key;&lt;BR /&gt;
cards;&lt;BR /&gt;
1&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table TEST as&lt;BR /&gt;
select *,&lt;BR /&gt;
coalesce (Main.Key, Minor._Key) as __Key&lt;BR /&gt;
from Main full join Minor&lt;BR /&gt;
on Main.Key = Minor._Key&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Fri, 11 Mar 2011 08:15:43 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-03-11T08:15:43Z</dc:date>
    <item>
      <title>proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27344#M6238</link>
      <description>I have two tables which are called Main and Minor, respectively. In table Main, there is a variable called KEY which takes value of 1, 2, 3, 4, 5, 6; In table Minor, there is also a variable called KEY which takes value of 1, 3, 4, 7.&lt;BR /&gt;
&lt;BR /&gt;
I ran following codes:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table TEST as&lt;BR /&gt;
select   *,&lt;BR /&gt;
	    coalesce (Main.Key, Minor.Key) as Key&lt;BR /&gt;
from	Main full join Minor&lt;BR /&gt;
on	Main.Key = Minor.Key&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
However, in the table TEST created, the variable Key only takes 1, 2 , 3, 4, 5, 6. My question is: why the Key variable wouldn't take 7?</description>
      <pubDate>Fri, 11 Mar 2011 05:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27344#M6238</guid>
      <dc:creator>littlestone</dc:creator>
      <dc:date>2011-03-11T05:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27345#M6239</link>
      <description>Hi.&lt;BR /&gt;
How about this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data main;&lt;BR /&gt;
input key;&lt;BR /&gt;
cards;&lt;BR /&gt;
1&lt;BR /&gt;
2&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data minor;&lt;BR /&gt;
input _key;&lt;BR /&gt;
cards;&lt;BR /&gt;
1&lt;BR /&gt;
3&lt;BR /&gt;
4&lt;BR /&gt;
7&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table TEST as&lt;BR /&gt;
select *,&lt;BR /&gt;
coalesce (Main.Key, Minor._Key) as __Key&lt;BR /&gt;
from Main full join Minor&lt;BR /&gt;
on Main.Key = Minor._Key&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 11 Mar 2011 08:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27345#M6239</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-11T08:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27346#M6240</link>
      <description>SAS creates the variables in the order it sees them. In your case 3 versions of the variable Key are created 2 from the original tables and 1 from the coalesce. The select statement determines the order, so in your case the key that is used is comming from the table Main. If you don't want to change the names try altering the order ie.&lt;BR /&gt;
&lt;BR /&gt;
select coalesce (Main.Key, Minor.Key) as Key, *</description>
      <pubDate>Fri, 11 Mar 2011 10:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27346#M6240</guid>
      <dc:creator>ISedgwick</dc:creator>
      <dc:date>2011-03-11T10:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27347#M6241</link>
      <description>What happens when proc sql has three variables all called the same thing?&lt;BR /&gt;
&lt;BR /&gt;
You have main.key, minor.key and the newly calculated key.</description>
      <pubDate>Fri, 11 Mar 2011 12:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27347#M6241</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-03-11T12:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27348#M6242</link>
      <description>Same answer, the one that you define first in you select clause.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 11 Mar 2011 13:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27348#M6242</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2011-03-11T13:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27349#M6243</link>
      <description>Thank you all for help. It turns out that ISedgwick's method works best.&lt;BR /&gt;
Again thank you very much.</description>
      <pubDate>Fri, 11 Mar 2011 18:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-question/m-p/27349#M6243</guid>
      <dc:creator>littlestone</dc:creator>
      <dc:date>2011-03-11T18:55:14Z</dc:date>
    </item>
  </channel>
</rss>

