如何在使用来自 WORK 的数据时通过 SAS EG ODBC 连接查询 SSMS?
How to query SSMS via SAS EG ODBC connection while using data from WORK?
有没有办法通过 SAS EG 中的 proc sql odbc 查询发送 SAS 数据集,以便它可以被 SQL 服务器接收和使用?
例如)
SAS 数据 WORK.A 包含 3 列 ID、col1、col2。
我在 Sql Management Studio 环境中有一个具有相同 ID 列的 table。
我想(以某种方式)按照下面的图 A 所示进行操作:
图A)
proc sql;
Connect to odbc("driver=SQL Server; database=SSMSDatabase; Server=SSMSServer");
create table WORK.B as
select * from connection to odbc
(
Select t1.*, t2.*
from SSMSTable1 t1
INNER JOIN WORK.A t2 ON t1.ID = t2.ID
);
disconnect from odbc;
quit;
这会在 SAS 中引发一个明显的错误,因为 SSMS 不理解 WORK.A 是什么...它期望执行纯 SSMS 代码。
我已经将在 SAS 中创建的宏变量传递给 SQL passthrough,以便在 WHERE 语句中使用,如图 B 所示,但这有其局限性(尤其是宏字符长度)并且不够优雅作为整体传递 table.
图B)
proc sql;
select cat("'",trim(ID),"'")
into :list1 separated by ","
from WORK.A;
quit;
%macro ODBCRun();
proc sql;
Connect to odbc("driver=SQL Server; database=SSMSDatabase; Server=SSMSServer");
create table WORK.B as
select * from connection to odbc
(
Select *
from SSMSTable1
WHERE ID IN (&list1.)
);
disconnect from odbc;
quit;
%mend;
%ODBCRun();
任何想法都会有所帮助。
在 SQL 服务器中创建一个临时 table,您可以对其执行稍后的直通查询。
示例:
libname SS odbc
dbmstemp=yes
noprompt="driver=SQL Server; database=SSMSDatabase; Server=SSMSServer"
;
* upload SAS data into SQL Server;
proc delete data=ss.'#idlist'n;
run;
data ss.'#idlist'n;
set WORK.A;
run;
* Use uploaded data in pass through query;
proc sql;
connect using SS as REMOTE; * reuses connection libref made;
create table WORK.B as
select * from connection to REMOTE
(
select t1.*, t2.*
from
SSMSTable1 t1
INNER JOIN
#idlist t2
ON
t1.ID = t2.ID
);
disconnect from REMOTE;
quit;
有没有办法通过 SAS EG 中的 proc sql odbc 查询发送 SAS 数据集,以便它可以被 SQL 服务器接收和使用?
例如)
SAS 数据 WORK.A 包含 3 列 ID、col1、col2。 我在 Sql Management Studio 环境中有一个具有相同 ID 列的 table。
我想(以某种方式)按照下面的图 A 所示进行操作:
图A)
proc sql;
Connect to odbc("driver=SQL Server; database=SSMSDatabase; Server=SSMSServer");
create table WORK.B as
select * from connection to odbc
(
Select t1.*, t2.*
from SSMSTable1 t1
INNER JOIN WORK.A t2 ON t1.ID = t2.ID
);
disconnect from odbc;
quit;
这会在 SAS 中引发一个明显的错误,因为 SSMS 不理解 WORK.A 是什么...它期望执行纯 SSMS 代码。
我已经将在 SAS 中创建的宏变量传递给 SQL passthrough,以便在 WHERE 语句中使用,如图 B 所示,但这有其局限性(尤其是宏字符长度)并且不够优雅作为整体传递 table.
图B)
proc sql;
select cat("'",trim(ID),"'")
into :list1 separated by ","
from WORK.A;
quit;
%macro ODBCRun();
proc sql;
Connect to odbc("driver=SQL Server; database=SSMSDatabase; Server=SSMSServer");
create table WORK.B as
select * from connection to odbc
(
Select *
from SSMSTable1
WHERE ID IN (&list1.)
);
disconnect from odbc;
quit;
%mend;
%ODBCRun();
任何想法都会有所帮助。
在 SQL 服务器中创建一个临时 table,您可以对其执行稍后的直通查询。
示例:
libname SS odbc
dbmstemp=yes
noprompt="driver=SQL Server; database=SSMSDatabase; Server=SSMSServer"
;
* upload SAS data into SQL Server;
proc delete data=ss.'#idlist'n;
run;
data ss.'#idlist'n;
set WORK.A;
run;
* Use uploaded data in pass through query;
proc sql;
connect using SS as REMOTE; * reuses connection libref made;
create table WORK.B as
select * from connection to REMOTE
(
select t1.*, t2.*
from
SSMSTable1 t1
INNER JOIN
#idlist t2
ON
t1.ID = t2.ID
);
disconnect from REMOTE;
quit;