@mitch0011 wrote:
Thanks, I tried your code suggestion:
proc sort data=Dataset1;
by ID PERSON; run;
proc sort data=Dataset2;
by ID PERSON; run;
data final;
merge Dataset1 Dataset2 (in=a);
by ID PERSON;
if a; run;
But I get a finaldataset of all observations from dataset1. it should only be a subset of those in dataset2 matching on ID/PERSON.
For instance, dataset1 has 1200 person month observations, which is for 100 persons since each one has 12 observations for each MONTH 1-12.
Dataset2 has 50 person observations that identify those records that I want to keep (Just ID/PERSON/VAR2, no MONTH variable).
Final dataset is expected to have 700 observations (50 persons from dataset2 and each of their 12 monthly obs from dataset1)
Which means that your "example" data posted behaves differently than your actual data. So you need to examine your example data and the real data.
Some things to consider: Are the values of the BY variables in the "dataset2" duplicated? That can cause an issue as that means that both data sets have multiple records for the by values and a merge typically does not perform well under that case. Show use the LOG from running the merge step. Copy the text from the log with all messages and note. On the forum open a text box with the </> icon and paste the text from the log.
... View more