*---Look up match: Using match id from one data set to find all match records

    from another data set;

 

data a;

  input id a;

  cards;

3 1

6 1

8 3

9 5

;

run;

 

data b;

  input id a;

  cards;

1 1

2 2

3 1

3 5

4 4

5 5

7 7

8 3

8 9

9 5

10 10

;

run;

 

data found;

  set a;

  do point = 1 to nobs;

    set b (keep=id a rename=(id=id2 a=a2)) point=point nobs=nobs;

    if id = id2 then

      do;

        a=a2;

          output;

        end;

  end;

run;

 

proc print data=found;

  title "Look Match Example";

run;

 

/* SAS Output:

 

       Look Match Example

 

  Obs    id    a    id2    a2

 

   1      3    1     3      1

   2      3    5     3      5

   3      8    3     8      3

   4      8    9     8      9

   5      9    5     9      5

 

*/