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 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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 266 views
  • 1 like
  • 2 in conversation