Matching a common field in 2 files

Reply
Frequent Contributor
Posts: 75

Matching a common field in 2 files

In file A, I have a column ID with many different rows of ID numbers (stored as char variables).

File B also has column ID & an extra Age column.

For all the ID in file A I want to find the ID with Age >12 in file B, how do I do so and extract them into a file?

Thank you

Respected Advisor
Posts: 3,887

Re: Matching a common field in 2 files

It's a bit difficult to give you a valid answer without you posting some representative sample data (2 data steps creating such data) and then telling us how the expected result should look like.

Here the recommendation of how to ask questions: https://communities.sas.com/docs/DOC-2263

Below some untested "pseudo code" which might or might not be what you're after.
proc sql;

     create table want as

     select b.*

     from TableA a, TableB b

     where a.id=b.id and b.age>12

     ;

quit;

Super User
Posts: 10,466

Re: Matching a common field in 2 files

May want

(select * from TableB where age>12) as b

instead as the where with the 'and' will limit the output of the TableA ids to only those as over age 12. Depends on how you meant 'all the ID in table A' to be interpretted.

Ask a Question
Discussion stats
  • 2 replies
  • 156 views
  • 0 likes
  • 3 in conversation