An error might occur if you use multiple instances of INNER JOIN syntax in the SQL procedure


The following error might occur if you use multiple instances of INNER JOIN syntax and you reference a table column in the ON clause before that table is referenced by the INNER JOIN:

ERROR: Correlated reference to column COL1 is not contained within a subquery.

This error is produced by an SQL procedure similar to the following:

proc sql;
   select * from table1 
   inner join table2 
   on table3.col1 = table1.col1 
   inner join table3 
   on table2.col1 = table1.col1 ; 
quit;

Note that the first ON clause contains a reference to TABLE3 before it is introduced as a table to be used in the query. To avoid this problem, be sure to reference the table prior to the INNER JOIN clause.