<?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: SQL Join with Two Tables, Need to Pull in Extra Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204282#M267046</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG - this was very helpful. I've never used merge, and at our firm we typically stick with PROC SQL to put our tables together...to keep everything consistent we all use it. I'm going to have to look more into this. It worked perfectly!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jul 2015 15:33:04 GMT</pubDate>
    <dc:creator>emmytheduck</dc:creator>
    <dc:date>2015-07-16T15:33:04Z</dc:date>
    <item>
      <title>SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204280#M267044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;New to SAS. I'm working on an attrition table for membership. I need to see which members stayed, left, or were new from 2014 to 2015. I have a table that is sorted by their ID in year 14 and year 15. I've been able to get it to a point where there is a flag for NEW, TERM, and RETAIN. However, the only data that I can see is the ID and their flagged status.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I thought, I'll SQL a table to join actual data (i.e. name, dob, address, etc.) to the table above. For some reason, when I pull member data into the table above, it deletes their info for about 10,000 lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code for the first table looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table combine as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.id as id14, b.idas id15, coalesce(a.id,b.id) as id_all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from _2014active a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; full join _2015active b on a.id= b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data everything14to15;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set combine;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if id14=id15then flag = 'Ret';&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if id14='' then flag = 'New';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if id15='' then flag = 'Ter';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THIS WORKS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To join "everything14to15" I have the following, and it does not work....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data = sas.memberdata nway missing;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class name dob address;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out = everything1 (drop = _type_ _freq_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table everything2 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.*, b.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from everything14to15 a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join everything1 b on a.id15=b.id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I apologize if this is confusing, but any help is appreciated. I need the first table and the second table to join together to show member information - not just their ID and status.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 21:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204280#M267044</guid>
      <dc:creator>emmytheduck</dc:creator>
      <dc:date>2015-07-15T21:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204281#M267045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems to me that merging your datasets would be simpler :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data members;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length status $3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;merge _2014active (in=in2014) _2015active (in=in2015);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if in2014 and in2015 then status="Ret";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else if in2014 then status="Ter";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else status="New";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(untested)&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 21:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204281#M267045</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-07-15T21:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204282#M267046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG - this was very helpful. I've never used merge, and at our firm we typically stick with PROC SQL to put our tables together...to keep everything consistent we all use it. I'm going to have to look more into this. It worked perfectly!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 15:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204282#M267046</guid>
      <dc:creator>emmytheduck</dc:creator>
      <dc:date>2015-07-16T15:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204283#M267047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do have a couple of questions. The (in=in2014) - is that naming a field associated with id? Because 'in2014' is not a field in the _2014active table. I'm just trying to understand the step. It works so well and I'd like to use it in the future!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 17:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204283#M267047</guid>
      <dc:creator>emmytheduck</dc:creator>
      <dc:date>2015-07-16T17:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204284#M267048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use SQL a lot myself, but for some purposes the datastep simply works better.&lt;STRONG&gt; IN=in2015&lt;/STRONG&gt; is a dataset option that creates a boolean variable named &lt;STRONG&gt;in2015&lt;/STRONG&gt; which indicates if &lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;_2015active&lt;/STRONG&gt; contributed to the merge. Thus, in the statement &lt;SPAN style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;merge _2014active (in=in2014) _2015active (in=in2015)&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;STRONG&gt;in2015&lt;/STRONG&gt; tells you if &lt;EM&gt;id&lt;/EM&gt; was present in dataset&lt;SPAN style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt; _2015active&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;. &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;By default, automatic variables created with the &lt;STRONG&gt;in=&lt;/STRONG&gt; option are not kept in output datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 20:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204284#M267048</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-07-16T20:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204285#M267049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for the clarification!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 21:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204285#M267049</guid>
      <dc:creator>emmytheduck</dc:creator>
      <dc:date>2015-07-16T21:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204286#M267050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you really need to do this with SQL then try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table members as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select * from&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select *, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Ter" as status&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from _2014active&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where id not in (select id from _2015active) )&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;union all&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select *, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when id in (select id from _2014active) then "Ret" else "New" end as status&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from _2015active )&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;order by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2015 02:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204286#M267050</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-07-17T02:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join with Two Tables, Need to Pull in Extra Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204287#M267051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, I was able to get most of it done with SQL, but I prefer the merge in this scenario. So thank you again for the knowledge!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2015 14:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Join-with-Two-Tables-Need-to-Pull-in-Extra-Data/m-p/204287#M267051</guid>
      <dc:creator>emmytheduck</dc:creator>
      <dc:date>2015-07-17T14:12:50Z</dc:date>
    </item>
  </channel>
</rss>

