Great idea ... I came up with the data step approach below but I think this works even better! I expanded the sample data to add a few more test cases in it. data trans; infile cards dlm=','; input store customer transaction; cards; 1, 10, 7171 2, 21, 8389 3, 40, 5118 3, 40, 8971 4, 40, 9008 4, 30, 10000 5, 88, 6673 5, 40,3333 6, 33,2222 3, 22,4555 7,22,5555 8,33,1111 9,33,8888 ; run; data storepairs; infile cards dlm=','; input store pair $; cards; 3, P1 4, P1 6, P2 8, P2 ; run; proc sql; create table transpair as select a.*, b.pair from trans as a , storepairs as b where a.store = b.store /*group by pair, customer having count(distinct store)=2*/ order by b.pair, a.customer, a.store ; quit; data transpair2; set transpair; by pair customer store; if first.customer then do; match = store; both = 0; end; if match ne store then both = 1; retain match both; if both = 1 then output; run; proc sql; create table final as select a.* from transpair as a , transpair2 as b where a.pair = b.pair and a.customer = b.customer ; quit; At least the two approaches should be able to give so insight into alternatives. EJ
... View more