title: SAS Pass-through SQL - Multiple DBs
body: <p>I want to retrieve from DB2 the list of records that matches the identifiers in a DB1 table, like a regular SAS subquery. How can I perform that with SAS pass-through SQL? </p>
  
  <p>Performing the (long and complex) SQL on db1 is too slow using a regular SAS SQL, that's why I am resorting to pass-through SQL instead.</p>
  
  <p>I tried the following but no luck:</p>
  
  <pre><code>proc sql;
      connect to db1 as A (user=&amp;userid. password=&amp;userpw.  database=MY_DB);
      connect to db2 as B (user=&amp;userid. password=&amp;userpw.  database=MY_DB);
  
      create table test as
      select * from connection to B (
          select * from schema.table
              Where ID_NUM =
                  (select * from connection to A
                        (select ID_NUM from schema2.table2)
                  );
          );
     disconnect from A;
     disconnect from B;
  quit;
  </code></pre>