DATA Step, Macro, Functions and more

Conditional join on two variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

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,256

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

View solution in original post


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

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: 110

Re: Conditional join on two variables

Thanks it worked! 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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