how to compare a variable in different datasets and find the same ones

Reply
Frequent Contributor
Posts: 122

how to compare a variable in different datasets and find the same ones

I have such a question. I have two datasets. A and B such as below

Dataset A

firm     name

1          A

1          B

...

2          A

2          C

...

Dataset B

firm     name

1          A

1          B

1          C

...

2          A

2          B

2          C

...

Dataset B is bigger than A. I want to find any observations that are not in A, but B. In the example above, it would be firm 1 name C and firm 2 name B. Please let me know how to do this. In actual dataset A, there is another variable date, for each date firm will have different names, but all these names are a subset of names in dataset B.

Super Contributor
Posts: 1,636

Re: how to compare a variable in different datasets and find the same ones

data want;

merge a(in=aa) b(in=bb);

by firm name;

if bb and not aa;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 214 views
  • 0 likes
  • 2 in conversation