BookmarkSubscribeRSS Feed
holcoje
Calcite | Level 5

I have a SAS table that is a subset of records (10 records) from a SQL Server table (20,837 records). I need to update the value of a column in the SQL Server table, but only for the records that also exist in my aforementioned SAS table. 

 

Specifically, if the record exists in the SAS table, then change the HISTORY_DATE value in the SQL Server table to today's date. 

 

What would be the cleanest way to do this? 

1 REPLY 1
SASKiwi
PROC Star

Is this going to be a  regular process or is it just a one-off? If the number of records stays quite low then building a WHERE statement using a macro variable is probably easiest:

libname SQLSRVR odbc noprompt = "server=SQLServerName;DRIVER=SQL Server Native Client 11.0;Trusted Connection=yes" DATABASE = MyDatabase schema = dbo;

proc sql;
  select quote(Key_Var) 
  into :Key_Var_List separated by "," 
  from SAS_Table;
quit;

proc sql;
 connect using SQLSRVR;
  execute(
  update table Want
  Date_Var = '20220322'
  where Key_Var in (&Key_Var_List)
  ) by SQLSRVR;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 517 views
  • 1 like
  • 2 in conversation