Ok, so keep in a if it exists:
data datac (drop=tmp:); merge dataa datab (rename=(kpi_1=tmp1 kpi_2=tmp2 x=tmp3); by id date; if kpi_1=. then kpi_1=tmp1; if kpi_2=. then kpi_2=tmp2; if x="" then x=tmp3; run;
I.e. rename the variables coming in from datab, then check if the variables after merge are missing, if so use b's version.
Note not tested, post test data in the form of a datastep.
... View more