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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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