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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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