11-11-2016 01:07 AM
I would like two combine the following two datasets.
I expect the following Dataset
I wrote following program
proc sort dataset1;
proc sort dataset2;
data final ;
merge dataset1 dataset2;
but I am getting multiple records in the result. Please advice. Thanks in advance !
11-11-2016 01:53 AM
Oh... you aren't actually joining on ID.
You want to join on ID from dataset one and mainID in dataset 2. You'll need to rename your variables and modify your sort accordingly.
11-11-2016 01:51 AM
11-11-2016 02:29 AM - edited 11-11-2016 02:30 AM
My main Dataset is Dataset-2 and I want to add detail information of corresponding ID. The detail information of Id is in form of P1 P2... etc in Dataset1 and that is why I am merging by ID.
11-11-2016 02:37 AM
Are you sure dataset 1 doesn't have duplicates?
Otherwise you could try IN to filter but you should first know why it's happening otherwise you may get unexpected results.
merge d1(in=in1) d2(in=in2);
if in2; *cant recall if it's the first or second that filters but hopefully you get the idea - keep only records from d1;
Need further help from the community? Please ask a new question.