I think I found a solution. I couldn't solve it in one step. Maybe there is a better way to solve it, but this gives the correct result. * 1. Create data set with no missing "concern"; data trans2; set transaction2; if concern ^= ""; run; * 2. Check if "concern" is in "have2" as well as "trans2".; data have2; set want; newid = strip(id)||"."||strip(concern); run; data trans2; set trans2; newid = strip(id)||"."||strip(concern); run; * Those in trans2 with no entry in have2 will have empty cells for variable "morestuff"; proc sql; create table test6 as select coalesce(a.id,b.id) as id, a.*, b.morestuff from trans2 a left join have2 b on (a.newid eq b.newid); quit; * Keep only those of test6 (origin: trans2) which have no entry in "morestuff", i.e. those which are not (yet) in have2, but with more information in trans2; data interim; set test6; keep id newid positive; if morestuff = "" then positive = 1; if positive = 1; run; * Transfer knowledge that there is more information in trans2 for specific observations in have2 to have2; data have2; merge have2 interim; drop newid; by id; run; * Single out those observations which have more information in trans2. Keep those variables which need to be concottonated to information in trans2. Here only "morestuff".; data morestuff; set have2; keep id morestuff; if positive = 1; run; * Just in case that there can be duplicates; proc sort data=morestuff; by id morestuff; run; data shortmorestuff; set morestuff; by id morestuff; if first.morestuff then output; run; * Add all relevant information from shortmorestuff to test6 (origin: trans2, but only relevant observations); * First: Create data set similar to interim, but with relevant information; data relevant; set test6; keep id concern ; if morestuff = ""; run; * Second: Bring together; proc sql; create table transwithadded as select coalesce(a.id, b.id) as id, a.*, b.* from relevant a natural full join shortmorestuff b ; * Attach transwithadded to have2; data result; set have2 transwithadded; drop positive ; run;
... View more