primary key - SAS Data step Merge/Modify 2 datasets but still keep the integrity constrants (pk) on master dataset -


i have code below

data master; input id name $ status $; datalines; 1    b    b 2    c    c 3       ;;;; run;  proc sql; alter table master add primary key (id); quit;  data transaction; input name $ status $; datalines;    f f    f e    e d    d b    z c    x ;;;; run;  proc sort data = master; name; run;  proc sort data = transaction; name; run; 

i merge transaction dataset master dataset, , update value master value transaction dataset. achieve this, use code below

data have; retain _maxid;  merge have addon; name; if id = . id = _maxid + 1; _maxid = max(id, _maxid); run; 

the result this

id   name   status 3         f 1    b      z 2    c      x 4    d      d 5    e      e 6    f      f 

however, master dataset reset, , lost primary key constraint on id column of master dataset.

as far know, merge, set , update command create new dataset, not update current dataset.

the modify statement 1 update current dataset, replacing merge statement above code modify not work.

i solve problem reinstate primary constraint on master dataset after merging, not solution imo.

is there other way this? appreciated , in advance.

as said, statement doesn't create new dataset modify, can use achieve goal. there sugi paper on using modify here

here code can use, i've set id equal current iteration works in example, check suitable actual purpose.

data master; modify master transaction; name; select (_iorc_);     when (%sysrc(_sok)) replace;     when (%sysrc(_dsenmr)) do;         id=_n_;         output;         _error_=0;         end;     otherwise;  end; run; 

there similar answered question here gives additional detail.

link:- similar statement merge sql in sas


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -