BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

hi guys,

I need your  help please Smiley Happy

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)

So this is  how i start with

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

Any thoughts please

1 ACCEPTED SOLUTION

Accepted Solutions
jakarman
Barite | Level 11

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 --<-----

View solution in original post

4 REPLIES 4
jakarman
Barite | Level 11

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 --<-----
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks for your response Jaap

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

jakarman
Barite | Level 11

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 --<-----
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1175 views
  • 0 likes
  • 2 in conversation