Hi.
Your problem sounds so much as a SQL query that my first impulse would be to advise you to the SQL procedure... Something that would say :
[pre]
PROC SQL ;
CREATE TABLE yourLib.yourResult AS
SELECT *
FROM yourLib.A, yourLib.B
WHERE ABS(a.x1 - b.x2) < 20000
AND b.z > 0
;
QUIT ;
[/pre]
However, if you feel more confortable with the Data step logic, your problem could be solved using two SET statements in the same Data step. The first one is for reading A one row at a time, and the second one for reading the whole B dataset each time a new observation is loaded from A. This can be done by controlling the second SET statement with a DO loop and a POINT option. POINT directs the SET statement to read only a specified record, instead of the implicit loop that it usually does.
Since, reading my explanations, I hardly understand myself, I think I'd best proceed to an example...
[pre]
DATA yourLib.yourResult ;
SET yourLib.A ;
DO B_row=1 TO B_size ;
SET yourLib.B POINT = B_row NOBS = B_size ;
IF ABS(x1 - x2) < 20000
AND z > 0 THEN OUTPUT ;
END ;
RUN ;
[/pre]
I still think that this solution looks less simple than the first one, especially if variable have the same names in datasets A and B (your have to rename them in the second solution, when SQL provides dataset.variable notation to avoid ambiguous references).
Besides, you could be advised to use more tricky -- yet efficent -- solutions as hash tables. Have a look to the HASH object documentation if you feel sane enough to code that kind of things...
Regards.
Olivier