BookmarkSubscribeRSS Feed
zdeb15
Calcite | Level 5

Hi all, There is a table in our data warehouse that contains an e-mail distribution group. I want to update that table from SAS ...Is there a way to update a SQL table from a SAS table? 

 

libname mylibref odbc datasrc=mydatasource schema=dbo;

 

proc Sql;
Connect to odbc (datasrc=mydatasource);

update [db].dbo.sqltable t1
set EmailList = (select EmailList
from SASemaillist1 t2
where t1.Team = t2.Team)
where team in (select t2.team from SASemaillist1 t2);


disconnect from odbc;

3 REPLIES 3
Reeza
Super User

You're mixing explicit SQL and implicit SQL there. You cannot do that. 

 

You need to find the SAS code that you need to run, not the SQL you're currently using and it should work directly from PROC EXPORT. 

You cannot use explicit SQL here because it only passes your query to the server, not your SAS data.

 

libname mylibref odbc datasrc=mydatasource schema=dbo;

 

proc Sql;
Connect to odbc (datasrc=mydatasource); *makes this explicit SQL;

update [db].dbo.sqltable as t1
set EmailList = (select EmailList
from SASemaillist1 t2
where t1.Team = t2.Team)
where team in (select t2.team from SASemaillist1 t2);


disconnect from odbc;

 

Instead your code should look like the following - note I don't think this is correct and don't know what the correct code should be, just pointing you in the right direction.

 

proc sql;
update mylibref.sqltable as t1
set EmailList = (select EmailList
from SASemaillist1 t2
where t1.Team = t2.Team)
where team in (select t2.team from SASemaillist1 t2);
quit;

 

zdeb15
Calcite | Level 5

Here is my updated code with errors:

 

 

libname SQL odbc datasrc=myDSN schema=dbo;


proc Sql;
 update SQL.EmailListingtest t1
  set EmailList = (select EmailList
   from SASemaillist1 t2
    where t1.Team = t2.Team)
     ,LastUpdateDt = (select LastUpdateDt
    from SASemaillist1 t2
     where t1.Team = t2.Team)
      where team in (select t2.team from SASemaillist1 t2);

 

I am getting these errors:

 

ERROR: Error binding parameters: [Microsoft][ODBC Driver 17 for SQL Server]Invalid precision value

ERROR: ROLLBACK issued due to errors for data set SQL.EmailListingtest.DATA.

 

 

Reeza
Super User
Pretty sure that's now a SQL update error, which I don't know how to resolve. I would suggest trying a simpler query to ensure that updates are occurring and then once you know it can be done, fine tuning your SQL query to get it working as desired.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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