## match merging

Solved
Super Contributor
Posts: 464

# match merging

hi guys,

So i am supposed to match two datasets and create 3 groups out of this merging.

I have Dataset A with x,y,z and Dataset B with x,y,z,indicator and i merge A and B by x,y

First group would be all leads from A that are in B where Indicator='Y'

Group two -- all leads from A in B where Indicator='N'

and Group three is one+two + remaining from B(non-matching)

Data one two three;

merge A(in=ina) B(in=inb);

by x,y;

if ina and inb and indicator='YES'  then do; type='A_yes'; output one three;end;

else if ina and inb and indicator='NO' then do; type='A_no;output two three;end;

else do; type='B';output three;end;

i dont get for "three" what i am supposed to get.I know  the logic for that group is not right but dont know how to set it  up  properly

The final group(group three) should have something like:

x y z indicator type

-----------------------------

1 2 3 yes A_yes

2 3 4 yes B

4 5 6 no A_no

2 2 3  no B

............

so combination from one two and  the non-matching from B bit not working for me.

i get something  like

x y z indicator type

-----------------------------

1 2 3 yes A_yes

. . . .         B

4 5 6 no A_no

. . . .       B

............

so for the non-matching i only  get the "type" values.Rest is missing

Accepted Solutions
Solution
‎09-01-2014 02:22 AM
Posts: 3,215

## Re: match merging

Us the nesting and ordereing in a more readable way:

if ina and inb  then do;

Select ;

When ( indicator='YES)  then do;

type='A_yes'; output one three;

end;

When ( indicator='NO' ) then do;

type='A_no;output two three;

end;

Otherwise ;  /* is this option possible ??  merged and indicatior not no or yes   */

end;

end;

if not ina and inb  then do;

type='B'; output  three;

end;

---->-- ja karman --<-----

All Replies
Solution
‎09-01-2014 02:22 AM
Posts: 3,215

## Re: match merging

Us the nesting and ordereing in a more readable way:

if ina and inb  then do;

Select ;

When ( indicator='YES)  then do;

type='A_yes'; output one three;

end;

When ( indicator='NO' ) then do;

type='A_no;output two three;

end;

Otherwise ;  /* is this option possible ??  merged and indicatior not no or yes   */

end;

end;

if not ina and inb  then do;

type='B'; output  three;

end;

---->-- ja karman --<-----
Super Contributor
Posts: 464

## Re: match merging

I tried with your code but still getting missing values for the third group

Posts: 3,215

## Re: match merging

I did also ask that question.

Is it possible type has other values as indicated? The place of otherwise....

If there is no join missing an e-file record those values normally coming from wil be missing.

Can you give more details test data what is not going confirm your expectations?

---->-- ja karman --<-----
Super Contributor
Posts: 464

## Re: match merging

it actually works now,weird.

Client_type is a new variable that i was trying to create with different values for each criteria but thanks for your time and help Jaap.

Cheers

🔒 This topic is solved and locked.