Hi,
I've got a table in SQL server and a table in SAS, with the same structure and a unique row identifier. I need to update a column in SQL table with the values from SAS table. Can it be done from SAS? I do not have ODBC or Access, but use PC Files for the SAS-SQL connection. Any help will be greatly appreciated.
libname sqlpcf pcfiles dsn="sqlpcf" user="....." password="....";
proc sql;
connect using sqlpcf;
/* Microsoft SQL Server T-SQL syntax goes inside the () characters */
execute (
EXEC dbo.uspGetEmployeeManagers 6
) by sqlpcf;
quit;
Can you post a code example of how you are accessing SQL Server via the SAS PC Files Server?
If you are able to load an SQL Server temporary table from SAS then you could run an SQL Server script to update from that.
If that isn't an option you could write your SAS data to a delimited flat file and then have an SQL Server script upload that.
When I overwrite SQL table with SAS table I do as in the code below.
In my current task though, SQL people do not want SQL table to be overwritten. Therefore, I can only update values in one column. The table in SQL is a control table which tells SAS which processes to be executed. It has a column - SAS_Run_Flag=0. When SAS finishes without error, SAS_Run_Flag changes to 1 in SAS temporary table. Then SAS_Run_Flag in SQL has to be updated with values from SAS temp table. Hope it makes sense.
Code for SQL table over-write:
LIBNAME DSAS01 pcfiles server=localhost port=9621 dsn=SAS_dSAS01 user=SASConnector password="";
PROC SQL;
CONNECT to pcfiles as myconn (server=localhost port=9621 dsn=SAS_dSAS01_&dsn_dst user=SASConnector password="");
SELECT * from connection to myconn
(
IF OBJECT_ID(%str(%')&OutFile%str(%'), 'U') IS NOT NULL
DROP TABLE &OutFile;
);
QUIT;
*-------------| Write the updated table |-----------------;
DATA dsas01.&OutFile;
SET &OutFile;
RUN;
libname sqlpcf pcfiles dsn="sqlpcf" user="....." password="....";
proc sql;
connect using sqlpcf;
/* Microsoft SQL Server T-SQL syntax goes inside the () characters */
execute (
EXEC dbo.uspGetEmployeeManagers 6
) by sqlpcf;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.