## Conditional join on two variables

Solved
Frequent Contributor
Posts: 136

# Conditional join on two variables

I am trying to remerge two datasets under the following conditions:

dataset1: more than one observation per id and multiple date per id

id   date  age sex

1  ..

2...

3...

4

4

5

I created dataset 2 and selected distint id and the min(date)

dataset 2, one observation per id

id  min_date

1

2

3

Now I want to remerge the data back to get all the other variables, how can I create an inner joint statement using both id and min(date) to get the other information specific to that date in the original dataset

Accepted Solutions
Solution
‎02-13-2016 03:49 PM
Super User
Posts: 5,884

## Re: Conditional join on two variables

Just inner join on Id and Date = min_date?

If I understand correctly you can do this on one pass of the data, avoiding the join.
You could use group by ID and do having date = min (date).
Data never sleeps

All Replies
Solution
‎02-13-2016 03:49 PM
Super User
Posts: 5,884

## Re: Conditional join on two variables

Just inner join on Id and Date = min_date?

If I understand correctly you can do this on one pass of the data, avoiding the join.
You could use group by ID and do having date = min (date).
Data never sleeps
Frequent Contributor
Posts: 136

## Re: Conditional join on two variables

Thanks it worked!

🔒 This topic is solved and locked.