Pergunta

I have a SQL Server 2012 machine hosting a database with a large amount of data that I query on a regular basis. In order to make the query, I need to upload a list of Unique IDs, then query for data related to those unique IDs. In order to keep things working smoothly with so much data and a slow connection, I'm using the PROC SQL pass-through facility to do the selecting. What I want to know is if I can also use the pass-through facility to do the inserting from a local SAS dataset? I'm currently connecting with a libname statement, and then with a "connect to" statement in PROC SQL, but that's not elegant.

I'd like to do something like:

connect to odbc as SQL_SERVER (datasrce=...);
INSERT INTO CONNECTION TO SQL_SERVER...

Can this be done?

Foi útil?

Solução

It's technically possible to do so, but probably not the best way.

You could put your insert data into a macro variable, and then use INSERT INTO with that information as if it were plain text in your program statement. You cannot do exactly what you were asking (unless you have a connection from SQL Server to SAS via SAS's ODBC drivers and have some stored proc that can access the SAS datasets? Not sure if that's possible.)

However, the better way is to use libname connection to create the table, and then use passthrough to do the selection.

libname sqlserv odbc (...);
proc sql;
connect to odbc as sql_server( ...);
create table sqlserv.temptable (select * from whatever);
select * from connection sql_server (... your other query, which can access temptable ...);
quit;

The thing to be careful of, is that these are two separate sessions, so you can't use a session-specific temporary table - you have to use a permanent table, or something else that would persist between sessions.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top