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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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