Your query will not return the desired result because every observation in Lookup will match every record in Main where Trans_type="O". You can avoid the inefficient OR condition with a UNION query such as : proc sql; create table Final as select A.*, B.account from Main as A inner join Lookup as B on A.token = B.token where A.Trans_Type ne "O" UNION ALL select A.*, B.account from Main as A left join Lookup as B on A.token = B.token where A.Trans_Type = "O"; quit; This will pull out every Main record that matches a Lookup observation plus every Main record that has Trans_Type="O". That seems to be what you want. PG
... View more