Piggybacking on @Ksharp's code here an option which modifies the master data set in place.
data master;
set sashelp.class;
run;
data trans;
length name $ 8 sex $ 1;
/* updates */
name='Robert';
sex='N';
output;
name='Thomas';
sex='A';
output;
/* inserts */
name='Ksharp';
sex='M';
output;
run;
data master(drop=_:);
modify master end=last;
if _n_=1 then
do;
dcl hash h1(dataset:'trans');
dcl hiter hh1('h1');
_rc=h1.defineKey('Name');
_rc=h1.defineData(all:'y');
_rc=h1.defineDone();
end;
/* updates */
if h1.find()=0 then
do;
replace;
_rc=h1.remove();
end;
/* inserts */
if last then
do;
_rc = hh1.first();
do while (_rc = 0);
output;
_rc = hh1.next();
end;
end;
run;
Please Note that for the Insert case all values for variables which only exist in the Master dataset but not in the Transaction dataset get retained (which is of course wrong).
If you don't have all variables in your transaction dataset then you need to use a "call missing()" for the Insert case for all variables which only exist in the master dataset.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.