Hello, As per your sample data, code which i have posted will work but if there is many to many relationship b/w your type of services and date then try the following SAS code...i have corrected it as per your requirement... proc sort data = table_A; by date id; run; proc sort data = table_B; by date id; run; data final; retain id service date; merge table_A(in = a) table_B(in = b); n = 1; by date id; if a and b then do; n + 1; n + n; end; if n > 1 then service = put(n,1.)||" A/B"; if a not eq b then do; n + 1; service = put(n,1.)||" "||strip(substr(service,8,1)); end; n = 1; if first.date EQ last.date then service = put(n,1.)||" "||strip(substr(service,2)); run; proc sort data = final(drop = n) nodupkey; by id service date; run; I hope this time this will produce the output as per your requirement...And note regarding MERGE statement is obivious as you are having many to many relations in your data... Thanks, Urvish
... View more