SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Update/Insert into SQL table from SAS

Reply
N/A
Posts: 0

Update/Insert into SQL table from SAS

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
SAS Employee
Posts: 5

Re: Update/Insert into SQL table from SAS

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;
Post a Question
Discussion Stats
  • 1 reply
  • 138 views
  • 0 likes
  • 2 in conversation