From: Andy Wong on
Hello all,

I want to merge dataset 1 and dataset 2 by ID and SubID.
Here is my example:

Dataset 1
ID SubID
10 1
10 3
10 5
20 2
20 4

Dataset 2
ID SubID Emp
10 1 10
10 2 20
10 3 30
10 4 40
10 5 50
20 1 10
20 2 20
20 3 30
20 4 40
20 5 50

I want my output to look like this:

ID SubID Emp
10 1 10
10 3 30
10 5 50
20 2 20
20 4 40

Thanks in advance for helping me.

Andy
From: Amar Mundankar on
On May 14, 12:47 am, Andy Wong <kaw...(a)gmail.com> wrote:
> Hello all,
>
> I want to merge dataset 1 and dataset 2 by ID and SubID.
> Here is my example:
>
> Dataset 1
> ID SubID
> 10 1
> 10 3
> 10 5
> 20 2
> 20 4
>
> Dataset 2
> ID SubID Emp
> 10 1 10
> 10 2 20
> 10 3 30
> 10 4 40
> 10 5 50
> 20 1 10
> 20 2 20
> 20 3 30
> 20 4 40
> 20 5 50
>
> I want my output to look like this:
>
> ID SubID Emp
> 10 1 10
> 10 3 30
> 10 5 50
> 20 2 20
> 20 4 40
>
> Thanks in advance for helping me.
>
> Andy

Hi Andy,
You can use the following code.

data one;
input ID SubID ;
cards;
10 1
10 3
10 5
20 2
20 4
;

Data two;
input ID SubID Emp ;
cards;
10 1 10
10 2 20
10 3 30
10 4 40
10 5 50
20 1 10
20 2 20
20 3 30
20 4 40
20 5 50
;
data three;
merge one(in = InOne) two;
by id subid;
if InOne;
run;
proc print data = three;
run;

Thanks and Regards,
Amar Mundankar.
From: Andy Wong on
On May 13, 11:28 pm, Amar Mundankar <amarmundan...(a)gmail.com> wrote:
> On May 14, 12:47 am, Andy Wong <kaw...(a)gmail.com> wrote:
>
>
>
>
>
> > Hello all,
>
> > I want to merge dataset 1 and dataset 2 by ID and SubID.
> > Here is my example:
>
> > Dataset 1
> > ID SubID
> > 10 1
> > 10 3
> > 10 5
> > 20 2
> > 20 4
>
> > Dataset 2
> > ID SubID Emp
> > 10 1 10
> > 10 2 20
> > 10 3 30
> > 10 4 40
> > 10 5 50
> > 20 1 10
> > 20 2 20
> > 20 3 30
> > 20 4 40
> > 20 5 50
>
> > I want my output to look like this:
>
> > ID SubID Emp
> > 10 1 10
> > 10 3 30
> > 10 5 50
> > 20 2 20
> > 20 4 40
>
> > Thanks in advance for helping me.
>
> > Andy
>
> Hi Andy,
> You can use the following code.
>
> data one;
>         input ID SubID ;
>         cards;
> 10 1
> 10 3
> 10 5
> 20 2
> 20 4
> ;
>
> Data two;
>         input ID SubID Emp ;
>         cards;
> 10 1 10
> 10 2 20
> 10 3 30
> 10 4 40
> 10 5 50
> 20 1 10
> 20 2 20
> 20 3 30
> 20 4 40
> 20 5 50
> ;
> data three;
>         merge one(in =  InOne) two;
>         by id subid;
>         if InOne;
> run;
> proc print data = three;
> run;
>
> Thanks and Regards,
> Amar Mundankar.- Hide quoted text -
>
> - Show quoted text -

Thanks!