Subsetting a Data set

Reply
Contributor
Posts: 66

Subsetting a Data set

Let;

data aa;

input Name $  Age Height;

datalines;

Adam 55 100

Jack 60 110

Stacy 42 105

Rabecca 32 100

Jacob 63 99

Jack 89 150

Don 100 140

;

data bb;

input Name $  Age;

datalines

Jack  50

Don 90

Tony 67

;

Here names Jack and Don are present in both the data sets. But have mismatching ages....which I do not care.

My question is

I want to create a new data set cc from aa such that it does not contain the the names which are in data set bb.

In above example jack( needs to deleted from both the rows) and don need to be deleted from data set aa to give data set cc.

Any suggestions?

Thanks.

Respected Advisor
Posts: 4,930

Re: Subsetting a Data set

Is SQL ok?

proc sql;

create table cc as

select * from aa where Name not in (select Name from bb);

quit;

PG
Contributor
Posts: 66

Re: Subsetting a Data set

Thanks PG Stats, Never thought I could get an answer this early...with in minutes. Thanks.

Contributor
Posts: 66

Re: Subsetting a Data set

Thanks Arthur.

PROC Star
Posts: 7,489

Re: Subsetting a Data set

or, with datastep:

proc sort data=aa;

  by name;

run;

proc sort data=bb;

  by name;

run;

data want;

  merge aa bb (in=inbb keep=name);

  by name;

  if not inbb;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 200 views
  • 0 likes
  • 3 in conversation