BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Angi
Obsidian | Level 7

Hi,

I have two datasets in long format that have a variable “ID” in common.

If DatasetB doesn’t have a matching ID with DatasetA, I want to delete unmatched cases in DatasetB.

Is there any way to do this without merging the two datasets?

Have DatasetA:

ID

VarA

VarB

1

Abcd

1232

1

Erfsdjdgr

94847

2

Fakjsdf;asie

5342

3

Kjdafjdh

0589576

3

Hfajdhfdh

143

Have DatasetB:

ID

VarX

VarY

2

124363

Abjdkafh

2

5463

Giagaojdfl

3

9378464

Nadfaei

5

23756

Nann

6

987543

Ueyrf

7

625364

Qodiafe

Want new_DatasetB

ID

VarX

VarY

2

124363

Abjdkafh

2

5463

Giagaojdfl

3

9378464

Nadfaei

Thank you for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The simplest way (create a new table, no sorting) would be:

proc sql;

create table new_datasetB as

select * from datasetB

where ID in (select ID from datasetA);

quit;

if you would prefer to modify datasetB (could be faster if datasetB is large) :

proc sql;

delete from datasetB

where ID not in (select ID from datasetA);

quit;

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

The simplest way (create a new table, no sorting) would be:

proc sql;

create table new_datasetB as

select * from datasetB

where ID in (select ID from datasetA);

quit;

if you would prefer to modify datasetB (could be faster if datasetB is large) :

proc sql;

delete from datasetB

where ID not in (select ID from datasetA);

quit;

PG

PG
Angi
Obsidian | Level 7

Thank you very much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 754 views
  • 1 like
  • 2 in conversation