Your text explanation does not match your expected results: You state newvar 4 should be 49. However, your explanation for newvar 4 is: "Place the value of advfnl2_c in "NEWVAR4" unless it's the same value as 'NEWVAR1' or 'NEWVAR2' or 'NEWVAR3'. If it is the same value then ues advfnl3_c.". In your example, advfnl2_c = 29 and that matches newvar3. According to your instructions, we should, therefore, set newvar4 to advfnl3_c (=34). Either your expected results are wrong, or your explanation is wrong. Regardless, you could something like the following logic (which adheres to your explanation -- not your expected result). I've re-named your variables for convenience: data new ; merge old1 old2; by idno; format newvar1-newvar4 3.; newvar1 = advfnl_1; if advfnl_c1 = newvar1 then newvar2 = advfnl_c2; else newvar2 = advfnl_c1 ; if advfnl_2 = newvar1 or advfnl_2 = newvar2 then newvar3 = advfnl_3; else newvar3 = advfnl_2; if advfnl_c2 = newvar1 or advfnl_c2 = newvar2 or advfnl_c2 = newvar3 then newvar4 = advfnl_c3; else newvar4 = advfnl_c2; run;
... View more