BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have to write a code in SAS that updates an existing table in SQL database from SAS file for the existing cases, and insert any new cases into the same table. Is this possible. If so how. I have SAS ver 9.1.3 and SAS/ACCESS for windows pc.

thanks
1 REPLY 1
Anitha_SAS
SAS Employee
Here is an example:

data master(index=(ssn));
input ssn : $11. nickname $5.;
datalines;
161-60-5881 chk1
160-58-1223 chk2
;
data trans;
input ssn : $11. tnicknam $5.;
datalines;
161-60-5881 Josh
160-58-1223 Kathy
134-56-9094 Meg
142-67-9888 Bill
;
proc sort data=trans;
by ssn;


data master;
set trans;
by ssn;
modify master key=ssn;
if _iorc_=%sysrc(_sok) then do;
nickname=tnicknam;
_error_=0;
put 'in replace';
replace master;
end;
else if (%sysrc(_dsenom)) then do;
_error_=0;
nickname=tnicknam;
put 'in insert';
output master;
end;
run;

proc print data=master;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Discussion stats
  • 1 reply
  • 1194 views
  • 0 likes
  • 2 in conversation