<?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: SAS Sql code for returning matches in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147304#M39028</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, for my part:&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt; WORK.TABLEA A&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; left join WORK.TABLEB B&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;The A after the dataset is an alias.&amp;nbsp; The alias is used throughout the rest of the code, so if I select A.VAR1, then I mean VAR1 from WORK.TABLEA.&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;The tableb has more columns, this does not matter, in the select statement I choose the variables&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;A.* = all variables from tablea&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;case B.STATUS -&amp;gt; I select no variables from B, only use B.STATUS to select if I get NA or not.&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;As for the code presented, I would put aliases on it, and also explain "what does not work" as you have various typos and things in the code:&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.*,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE(select THIS.STATUS from TABLEB THIS where A.ID=THIS.ID),"N/a") as AVAILABILITY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLEA A;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note in the above I am using a small trick.&amp;nbsp; The coalesce function takes the first non-missing in the list of variables, so if the select subclause returns something then that is what the data will be, if there is not record then NA is used.&amp;nbsp; Note also the alias used A = TABLEA, THIS = TABLEB in the subclause.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;Also a good idea to format code in a readable fashion using aligned indents, etc. just for readability.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Sep 2014 19:46:02 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-09-17T19:46:02Z</dc:date>
    <item>
      <title>SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147293#M39017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have two simple&amp;nbsp; tables, A and B&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table A looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;name&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt; Comment&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Toyota&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;111&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Nissan&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;124&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Range Rover&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Best&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Table B looks like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;name&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Comment&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Status&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Toyota&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Sold&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;111&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Nissan&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Available&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;171&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Ford&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Excellent&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Sold&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I want a SAS SQL programme&amp;nbsp; to look at table B and report status for each vehicle&amp;nbsp; on table A( availability column)&amp;nbsp; according to ID as follows, and return N/a when there is no ID match as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;name&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;comment&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Availability&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Toyota&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Sold&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;111&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Nissan&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Good&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Available&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;124&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Range Rover&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Best&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;N/a&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 17:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147293#M39017</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-09-16T17:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147294#M39018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Basic SQL left join:&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;select A.*, case B.ID when . then "N/a" else B.status end as availability&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from A left join B on A.ID=B.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;The presence of &lt;STRONG&gt;name&lt;/STRONG&gt; and &lt;STRONG&gt;comment&lt;/STRONG&gt; in table B is a bit puzzling. What if they don't match the values in table A for the same &lt;STRONG&gt;ID&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>Tue, 16 Sep 2014 17:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147294#M39018</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-16T17:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147295#M39019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG Stats&lt;/P&gt;&lt;P&gt;Your code did not work, you did not&amp;nbsp; include the create table statement,&amp;nbsp; did I miss something?Please help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 08:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147295#M39019</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-09-17T08:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147296#M39020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The key that PGStats is making is that you need to use a Left Join in SQL on ID:&lt;/P&gt;&lt;P&gt;data tablea;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=123; name="Toyota"; comment="Good"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=111; name="Nissan"; comment="Good"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=124; name="Range Rover"; comment="Best"; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data tableb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=123; name="Toyota"; comment="Good"; status="Sold"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=111; name="Nissan"; comment="Good";status="Available";&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=171; name="Ford"; comment="Excellent";status="Sold";&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; A.ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.NAME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.COMMENT,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case&amp;nbsp; when B.STATUS="" then "N/a"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else B.STATUS end as STATUS&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; WORK.TABLEA A&lt;/P&gt;&lt;P&gt;&amp;nbsp; left join WORK.TABLEB B&lt;/P&gt;&lt;P&gt;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.ID=B.ID;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 09:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147296#M39020</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-17T09:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147297#M39021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using Coalesce function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select a.*, coalesce(b.status, "N/A") as availability from a left join b on a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 09:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147297#M39021</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-17T09:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147298#M39022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RW9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is all my real tables have too many columns and will take time selecting all with that select statement.any easier way to include the&amp;nbsp; extra column with results without using select statement?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 09:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147298#M39022</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-09-17T09:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147299#M39023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, if its laziness your after...&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; A.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case&amp;nbsp; when B.STATUS="" then "N/a"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else B.STATUS end as STATUS&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; WORK.TABLEA A&lt;/P&gt;&lt;P&gt;&amp;nbsp; left join WORK.TABLEB B&lt;/P&gt;&lt;P&gt;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.ID=B.ID;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I would advise that you should be able to build an SQL in many ways in which variables are explicitly stated - there are reasons not to use the asterix notation.&amp;nbsp; Most SQL editors have a an object browser where you can drag column names out of to save typing, you could do the same with a proc contents, or generate the code from sashelp.vcolumns etc. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 09:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147299#M39023</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-17T09:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147300#M39024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG's code missing some key variables .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;select A.*, case B.ID when . then "N/a" else B.status end as availability&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;from A&amp;nbsp; &lt;SPAN style="text-decoration: underline;"&gt;natural&amp;nbsp; &lt;/SPAN&gt;left join B&amp;nbsp; ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;Xia Keshan&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 13:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147300#M39024</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-17T13:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147301#M39025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You never requested the creation of a dataset, you said you wanted to "&lt;EM style="font-size: 13.3333330154419px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;report status for each vehicle&lt;/EM&gt;". That is what a SELECT statement (without a CREATE) does. If you want to create a table, add CREATE TABLE MYREPORT AS in front of the select clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 14:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147301#M39025</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-17T14:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147302#M39026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN-CA" style="font-family: Arial, sans-serif;"&gt;It all depends whether &lt;/SPAN&gt;you want to join on NAME and COMMENT or not. These fields didn’t look like keys to me, when an apparently unique ID is available. - PG&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 14:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147302#M39026</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-17T14:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147303#M39027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RW9 sorry I'm not familiar with the join function in SQL&amp;nbsp; especially this part&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; WORK.TABLEA A&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; left join WORK.TABLEB B&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;What does the A after " TableA" reffers to? and and also what does the B after after TABLE B?&amp;nbsp; Note my real table B has more columns to the right, will it work with the code?&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;What about this code although still &lt;/SPAN&gt;doesn't&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt; work? any suggestions?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;proc sql non print;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;create table want as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;select tablea.* , case when exists ( select&amp;nbsp; status from tableb where tablea.id=tableb.id) then cats&amp;nbsp; (status) &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;else 'N/a'&amp;nbsp; end as availability&amp;nbsp; from tablea;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;quit;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 18:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147303#M39027</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-09-17T18:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147304#M39028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, for my part:&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt; WORK.TABLEA A&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; left join WORK.TABLEB B&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;The A after the dataset is an alias.&amp;nbsp; The alias is used throughout the rest of the code, so if I select A.VAR1, then I mean VAR1 from WORK.TABLEA.&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;The tableb has more columns, this does not matter, in the select statement I choose the variables&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;A.* = all variables from tablea&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;case B.STATUS -&amp;gt; I select no variables from B, only use B.STATUS to select if I get NA or not.&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;As for the code presented, I would put aliases on it, and also explain "what does not work" as you have various typos and things in the code:&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.*,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE(select THIS.STATUS from TABLEB THIS where A.ID=THIS.ID),"N/a") as AVAILABILITY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLEA A;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note in the above I am using a small trick.&amp;nbsp; The coalesce function takes the first non-missing in the list of variables, so if the select subclause returns something then that is what the data will be, if there is not record then NA is used.&amp;nbsp; Note also the alias used A = TABLEA, THIS = TABLEB in the subclause.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;Also a good idea to format code in a readable fashion using aligned indents, etc. just for readability.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Sep 2014 19:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147304#M39028</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-09-17T19:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147305#M39029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI, RW9&lt;/P&gt;&lt;P&gt; Your coalesce code is showing an error are you sure the syntax is correct?&lt;/P&gt;&lt;P&gt;I have tried to use the left join function but this seems to insert&amp;nbsp; additinal&amp;nbsp; linae on my orginal tablea, don't know why.I'm trying your coalesce code but it is giving an error, to avoid confusion my first table is called car and the second is called car1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you help&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 07:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147305#M39029</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-10-09T07:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147306#M39030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah yes, missing a bracket (the select within brackets is a subquery):&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.*,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE((select THIS.STATUS from TABLEB THIS where A.ID=THIS.ID),"N/a") as AVAILABILITY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLEA A;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 08:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147306#M39030</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-10-09T08:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147307#M39031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RW9,&lt;/P&gt;&lt;P&gt;The code does not work for reasons that are not syntax based. The problem with left join is that the programme adds extra lines on table a in case of duplicates on table b. All I want is something equivalent to excel vlookup, as table b has more lines and duplicates that i dont need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL style="list-style-type: upper-alpha;"&gt;&lt;LI&gt;Thanks.&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 17:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147307#M39031</guid>
      <dc:creator>zetter</dc:creator>
      <dc:date>2014-10-09T17:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Sql code for returning matches</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147308#M39032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well question 1 would then be, if you have duplicates, which of the duplicates you want to return the result of?&amp;nbsp; Is it by date, sequence number etc.&amp;nbsp; Once you identify what you want your single record to be then update the inner select to only select that row, maybe you just want&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table WANT as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.*,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE((select THIS.STATUS from TABLEB THIS where A.ID=THIS.ID and THIS.DATE=(select max(B.DATE) from TABLEB B where B.ID=THIS.ID)),"N/a") as AVAILABILITY&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; font-size: 13.33px; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 13.33px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLEA A;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;quit;#&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again it is exactly the same thing with a left join. Just clearly identify in your from clause what data should be coming into the join, eliminate duplicates at that stage, for instance if you assume that sold is more important then available do:&lt;/P&gt;&lt;P&gt;from&amp;nbsp; (select ID,MAX(case when STATUS="sold" then 2 else 1 end) as MAX_STATUS from TABLEA group by ID)&lt;/P&gt;&lt;P&gt;This will then give one record per ID with sold preferred above available.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 18:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Sql-code-for-returning-matches/m-p/147308#M39032</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-10-09T18:25:56Z</dc:date>
    </item>
  </channel>
</rss>

