我正在尝试在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;
但它似乎不喜欢在连接之前添加连接。这是正确的方法,还是我错过了什么?
感谢。
答案 0 :(得分: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;