<?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 proc sql left join with case when created variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418372#M102768</link>
    <description>&lt;P&gt;dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am trying to join 3 tables using proc sql and i have to use a variable (field) that I created with case when condition (as variable1). I need to merge this new variable1 to the 3rd table and sas is throughing off an error that it can't locate the variable1 (as it is created and not there on the 3 datasets). How can I join using the newly created variable?&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table new as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select a.*, case when&amp;nbsp;&amp;nbsp;(a.statuses=' ') and (a.reasons='') then a.check&lt;BR /&gt;&amp;nbsp;when a.statuses =' ' then a.check_bp&lt;BR /&gt;&amp;nbsp;else a.statuses end as&amp;nbsp;current_status,b.height,c.weight&lt;/P&gt;&lt;P&gt;from one as a left join two as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on (a.id=b.id)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left join three as c&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on (&lt;STRONG&gt;current_status&lt;/STRONG&gt;=c.status); quit;&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found in the contributing tables: current_status.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&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;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2017 06:22:44 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2017-12-05T06:22:44Z</dc:date>
    <item>
      <title>proc sql left join with case when created variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418372#M102768</link>
      <description>&lt;P&gt;dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am trying to join 3 tables using proc sql and i have to use a variable (field) that I created with case when condition (as variable1). I need to merge this new variable1 to the 3rd table and sas is throughing off an error that it can't locate the variable1 (as it is created and not there on the 3 datasets). How can I join using the newly created variable?&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table new as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select a.*, case when&amp;nbsp;&amp;nbsp;(a.statuses=' ') and (a.reasons='') then a.check&lt;BR /&gt;&amp;nbsp;when a.statuses =' ' then a.check_bp&lt;BR /&gt;&amp;nbsp;else a.statuses end as&amp;nbsp;current_status,b.height,c.weight&lt;/P&gt;&lt;P&gt;from one as a left join two as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on (a.id=b.id)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left join three as c&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on (&lt;STRONG&gt;current_status&lt;/STRONG&gt;=c.status); quit;&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found in the contributing tables: current_status.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 06:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418372#M102768</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-12-05T06:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql left join with case when created variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418375#M102769</link>
      <description>Try to use the CALCULATED  key word.</description>
      <pubDate>Tue, 05 Dec 2017 07:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418375#M102769</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-12-05T07:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql left join with case when created variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418455#M102789</link>
      <description>&lt;P&gt;thank you LinusH for replying. It didn't work with calculated. I had to create a view with another select statement and pick it from there to join the tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create view v_new as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&amp;nbsp;&lt;SPAN&gt;case when&amp;nbsp;&amp;nbsp;(a.statuses=' ') and (a.reasons='') then a.check&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;when a.statuses =' ' then a.check_bp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;else a.statuses end as&amp;nbsp;current_status,id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;from one a;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;create table new as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select a.*, v.current_status,b.height,c.weight&lt;/P&gt;&lt;P&gt;from one as a left join two as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on (a.id=b.id)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join v_new as v&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on (b.id=v.id)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left join three as c&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on (v.current_status=c.status); quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 12:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-with-case-when-created-variable/m-p/418455#M102789</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-12-05T12:31:41Z</dc:date>
    </item>
  </channel>
</rss>

