<?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: Complex Join in PROC SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365903#M64800</link>
    <description>Of you just want to fix your existing SQL: SAS SQL doesn't allow three level naming. Since your sub query is with a WORK table you'll be fine just to remove that part since WORK is implied when the linked is omitted. If you are in a similar situation with a table from a permanent library you need to use an alias on the from clause.</description>
    <pubDate>Sat, 10 Jun 2017 11:48:13 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2017-06-10T11:48:13Z</dc:date>
    <item>
      <title>Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365849#M64784</link>
      <description>&lt;P&gt;I'm trying to convert a join that works in SQL to an equivalent in PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One table has a listing of test results.&amp;nbsp; A separate table has a new test result that is less timely than the first table.&amp;nbsp; I want the less timely result from the 2nd table to be repeated in the 1st table until a new 2nd table result comes along.&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;PRE&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_PROCESS_LAB_CORRELATED AS 
   SELECT t1.PLANT_NUM, 
          t1.COMMODITY_COD, 
          t1.COMMODITY_NAM, 
          t1.LAB_BOARD_DAT_COD, 
          t1.PLANT_NAM, 
          t2.Purity_Avg_pct
      FROM WORK.PURITY t2
    left outer join
    MFGNPRO.PROCESS_LAB_CORRELATED_TAB t1
     ON  (t1.PLANT_NUM = t2.PLANT_NUM) AND
     t2.DateTime = ( SELECT MAX(WORK.PURITY.DateTime) FROM WORK.PURITY 
	WHERE WORK.PURITY.DateTime &amp;lt;= t1.LAB_BOARD_DAT_COD);
QUIT;&lt;/PRE&gt;&lt;P&gt;The error I get seems to be around MAX(WORK.PURITY.DateTime) : ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, ), *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=. &amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Enterprise Guide versoin 7.13 HF5 64-bit&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>Fri, 09 Jun 2017 22:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365849#M64784</guid>
      <dc:creator>AJRowe</dc:creator>
      <dc:date>2017-06-09T22:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365851#M64785</link>
      <description>&lt;P&gt;Can you post your actual log please.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 22:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365851#M64785</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-09T22:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365852#M64786</link>
      <description>&lt;P&gt;It would be better if you post a sample and what the output should look like.&lt;BR /&gt;&lt;BR /&gt;Maybe this example will help out. Here are two samples I had quick access to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.sample1;
infile cards expandtabs truncover;
input mgrno	announcement : mmddyy10.;
format announcement mmddyy10.;
cards;
9385	9/16/09
62890	9/14/08
;
run;


data work.sample2;
 infile cards expandtabs truncover;
input mgrno	fdate  : mmddyy10.	cusip;
format fdate mmddyy10.;
cards;
9385	12/31/07	12345
9385	12/31/06	12345
9385	12/31/08	12345
9385	12/31/09	12345
9385	12/31/10	12345
9385	12/31/11	12345
9385	12/31/07	23456
9385	12/31/08	23456
9385	12/31/07	34567
9385	12/31/07	78911
9385	12/31/08	78912
62890	9/13/08	34567
62890	9/13/07	12345
62890	9/13/06	12345
62890	9/13/11	22345
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As far as I can understand want you want to do, the code will look&amp;nbsp;like the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE work.want AS 
   SELECT a.mgrno, a.announcement, b.fdate
   FROM work.sample1 as a 
   LEFT JOIN work.sample2 as b 
   ON  a.mgrno = b.mgrno 
   WHERE b.fdate &amp;lt;= a.announcement
   GROUP BY b.mgrno HAVING b.fdate=max(b.fdate);
QUIT; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 22:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365852#M64786</guid>
      <dc:creator>Yegen</dc:creator>
      <dc:date>2017-06-09T22:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365903#M64800</link>
      <description>Of you just want to fix your existing SQL: SAS SQL doesn't allow three level naming. Since your sub query is with a WORK table you'll be fine just to remove that part since WORK is implied when the linked is omitted. If you are in a similar situation with a table from a permanent library you need to use an alias on the from clause.</description>
      <pubDate>Sat, 10 Jun 2017 11:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365903#M64800</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-06-10T11:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365930#M64810</link>
      <description>&lt;P&gt;Will do, next time.&amp;nbsp; Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 19:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365930#M64810</guid>
      <dc:creator>AJRowe</dc:creator>
      <dc:date>2017-06-10T19:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365931#M64811</link>
      <description>&lt;P&gt;That query structure worked for me.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 19:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365931#M64811</guid>
      <dc:creator>AJRowe</dc:creator>
      <dc:date>2017-06-10T19:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Join in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365932#M64812</link>
      <description>&lt;P&gt;Thanks for the suggestions.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 19:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complex-Join-in-PROC-SQL/m-p/365932#M64812</guid>
      <dc:creator>AJRowe</dc:creator>
      <dc:date>2017-06-10T19:14:08Z</dc:date>
    </item>
  </channel>
</rss>

