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.