简体   繁体   English

SAS传递SQL - 多个DB

[英]SAS Pass-through SQL - Multiple DBs

I want to retrieve from DB2 the list of records that matches the identifiers in a DB1 table, like a regular SAS subquery. 我想从DB2中检索与DB1表中的标识符匹配的记录列表,如常规SAS子查询。 How can I perform that with SAS pass-through SQL? 如何使用SAS传递SQL执行此操作?

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. 使用常规SAS SQL在db1上执行(长而复杂)SQL太慢了,这就是我使用传递SQL的原因。

I tried the following but no luck: 我试过以下但没有运气:

proc sql;
    connect to db1 as A (user=&userid. password=&userpw.  database=MY_DB);
    connect to db2 as B (user=&userid. password=&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;

If you're connecting to single DB2 instance and joining two tables in different schemas/databases, the following should work for you: 如果您要连接到单个DB2实例并在不同的模式/数据库中连接两个表,则以下内容适用于您:

proc sql;
    connect to db2 as B (user=&userid. password=&userpw.  database=MY_DB);

    create table test as
    select * from connection to B (
            /* here we're in DB2 SQL */
        select t1.* from schema.table as t1
                inner join schema2.table2 as t2
            on t1.ID_NUM = t2.ID_NUM
        );
   /* automatic disconnect at PROC SQL boundary */
quit;

If you talk to two different servers/two user accounts a heterogenous join without pass-through could be used. 如果您与两个不同的服务器/两个用户帐户通信,则可以使用不通过传递的异构连接。 Then the expected number of ID_NUM values would be important. 那么期望的ID_NUM值的数量将是重要的。

You can't perform a pass-through query to another pass-through query, unless your two databases are naturally connected in some way that you could take advantage of in the native system. 您不能对另一个传递查询执行传递查询,除非您的两个数据库以某种方式自然连接,您可以在本机系统中利用这些查询。

The only way to do something like this would be to perform the connection to A query and store that result in a macro variable (the list of ID_NUMs), and then insert that macro variable into the query for connection to B . 执行此类操作的唯一方法是执行与connection to A查询的connection to A并将结果存储在宏变量(ID_NUM列表)中,然后将该宏变量插入查询以connection to B

It might well be better to not explicitly use passthrough here, but instead to use libname and execute the query as you would normally. 最好不要在这里明确使用passthrough,而是使用libname并像往常一样执行查询。 SAS may well help you out here and do the work for you without actually copying all of B's rows in first. SAS可能会帮助你在这里完成工作,而不是先实际复制B的所有行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM