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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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