I have two datasets, both in the following format:

ID Time Var_1 Var_2 Var_3 Var_k
ID Time Var_1 Var_2 Var_3 Var_k
I'm trying to add some variables from dataset #2 to dataset #1 so that the latter looks like this:
ID Time Var_1 Var_2 Var_3 Var_from_dataset#2 Var_k
The problem is that the datasets are not perfect matches in terms of how often each ID appears for each time unit. In datatset#1, each ID has an observation for each time unit. In dataset#2, some IDs don't have observations for some time units, so they're omitted (not coded as missing). Because of this, dataset#2 has fewer observations total, and simply pasting in a variable to dataset#1 wouldn't work. Also, not all of the IDs which exist in dataset#2 exist in dataset#1.

Is there a way to move the data I need from dataset#2 to dataset#1 while making sure each observation matches the right ID and time? Or to somehow automatically create a bunch of missing values for observations which don't exist in dataset#2?

Thanks in advance.