Help using Base SAS procedures

Extracting records based on a field in another dataset

Reply
N/A
Posts: 1

Extracting records based on a field in another dataset

I'm a SAS beginner facing what seems to be an advanced question not addressed in the Enterprise Guide. Two datasets A and B both contain the same ID field.  Dataset B has a Region field.  Each ID in dataset B has a unique Region.  I want to extract all the records in dataset A which have Region = 1 in dataset B.  (Or Region = whatever value I choose.)  Is there something obvious I am overlooking?

Or equally useful, I suppose, would be an approach to add the Region field to dataset A based on its values in Dataset B.

Respected Advisor
Posts: 4,641

Re: Extracting records based on a field in another dataset

To create a new dataset with all fields from A plus the Region you could use:

proc sql;

create table C as

select A.*, B.region

from A left join B on A.id=B.id;

quit;

PG

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