BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VSht
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
VSht
Obsidian | Level 7

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;

 

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

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.

VSht
Obsidian | Level 7

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;

VSht
Obsidian | Level 7

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 569 views
  • 0 likes
  • 2 in conversation