0

我正在尝试在 SQL 直通中合并 SAS 表,以帮助减少查询 SQL 数据库所需的时间。目前我只是按原样使用直通,大约需要 8-9 个小时才能从表中提取所有内容,然后再选择我想要的内容。

目前,直通看起来像这样:

proc sql;
    connect to ODBC as CAW(datasrc = "CAW_ULI_STATIC");
    create table test  as 
        select aelref, aelprdtyp, aelsubtyp, aelloc, aelopndte,
         hdscontrolopendate, hdscontrolclosedate, hdscontrolaction,
        from connection to CAW (
                                select aelref, aelprdtyp, aelsubtyp, aelloc, aelextnbr, aelbrnpfx, aelitnnbr, aelopndte,
                                         aelclddte, hdscontrolopendate, hdscontrolclosedate, hdscontrolaction
                                from PUBLIC_withpersonal_short.Vwhdscisagrmnt (nolock)

                                where HDSControlACTION <> 'D' 
                                    and aelsubtyp in (1, 2, 3, 4, 5, 10, 20, 21)
                                order by aelref, hdscontrolopendate, hdscontrolclosedate
                                ); 
disconnect from CAW;
; 
quit;

但是我现在正在尝试使用另一个 SAS 数据集来缩小我通过左连接从直通中提取的范围,所以它看起来像这样:

    proc sql;
        connect to ODBC as CAW(datasrc = "CAW_ULI_STATIC");
        create table test  as 
            select a.*, aelref, aelprdtyp, aelsubtyp, aelloc, aelopndte,
             hdscontrolopendate, hdscontrolclosedate, hdscontrolaction,
            from Import1 a left join connection to CAW (
                                    select aelref, aelprdtyp, aelsubtyp, aelloc, aelextnbr, aelbrnpfx, aelitnnbr, aelopndte,
                                             aelclddte, hdscontrolopendate, hdscontrolclosedate, hdscontrolaction
                                    from PUBLIC_withpersonal_short.Vwhdscisagrmnt (nolock)

                                    where HDSControlACTION <> 'D' 
                                        and aelsubtyp in (1, 2, 3, 4, 5, 10, 20, 21)
                                    order by aelref, hdscontrolopendate, hdscontrolclosedate
                                    ); 
    disconnect from CAW b;
    on a.ANUM = b.aelextnbr
    ; 
    quit;

但它似乎不喜欢在连接之前添加一个连接。这是正确的方法吗,还是我错过了什么?

谢谢。

4

1 回答 1

0

不会。您的第二个 SQL 查询只会减少写入的记录数,但 SAS 仍需要从您的 ODBC 连接中提取所有记录才能执行连接。

将 IMPORT1 SAS 数据集推送到 ODBC 数据库并在那里执行连接。

或者,如果记录数足够少,则使用宏变量生成 ANUM 值列表以将其包含在查询中。像这样的东西:

 proc sql noprint ;
   select ANUM into :list separated by ',' from import1;
   connect .... ;
   select ... from connection to odbc
    (... where aelextnbr in (&list)
    );
 quit;
于 2016-12-30T15:22:01.867 回答