If the ID from data set 1 exists in dataset 2, I would like to create a new variable called flag in dataset 2 and it =1 and =0 otherwise. This is shown below. I tried using merge, but couldn't find a good way to do this. any help would be great.
Data 1:
ID
X1
X2
54
9
3
55
3
2
56
2
0
57
4
4
58
4
1
59
6
8
60
1
7
Data 2:
ID
Y1
Y2
Y3
54
55
79
55
55
83
61
55
56
74
77
60
57
64
88
56
60
87
78
83
61
84
87
77
62
78
68
50
63
89
59
52
64
74
77
60
65
55
79
55
Desired data:
ID
Y1
Y2
Y3
FLAG
54
55
79
55
1
55
83
61
55
1
56
74
77
60
1
57
64
88
56
1
60
87
78
83
1
61
84
87
77
0
62
78
68
50
0
63
89
59
52
0
64
74
77
60
0
65
55
79
55
0
... View more