Hi, Hope it works...In below macro no_of_vars parameter represents matching columns to be compare...like aa1,aa2,aa3, and bb1,bb2,bb3 and so on...so pass the value accordingly... Here you only have 1 common column like aa1 and bb1.... %macro obs_identify(no_of_vars =); proc contents data = one noprint out = one_list(keep = name where = (name ^in ("Cusip" "Year"))); run; proc contents data = two noprint out = two_list(keep = name where = (name ^in ("Cusip" "Year"))); run; proc sql noprint; select name into :one_list separated by "," from both_list; select two_name into :two_list separated by "," from both_list; quit; proc sql; create table both as select coalesce(a.cusip,b.cusip) as cusip, coalesce(a.year,b.year) as year, &one_list.,&two_list. case when a.cusip = b.cusip then "Match" when aa = . and bb = . then "Match" /* Loop for Series of Matching Columns */ %do i = 1 %to &no_of_vars.; when bb&i. = . then "Two" when aa&i. = . then "One" %end; else "Match" end as source from one as a full join two as b on a.cusip = b.cusip; quit; %mend; %obs_identify(no_of_vars = 1); -Urvish
... View more