Help using Base SAS procedures

interview question

Reply
Contributor
Posts: 70

interview question

Hi all

    I have two datasets.A and B as follows

    A                        B

Eid                       Eid

    1                        3

    2                        4

    3                        5

I need o/p as follows

Eid

1

2

4

5

I dont want value 3 in o/p dataset.Can anybody help me to solve this.

Thanks & Regards

Rawindarreddy

Respected Advisor
Posts: 3,124

Re: interview question

data a;

  input v;

  cards;

  1

  2

  3

  ;

  data b;

  input v;

  cards;

  3

  4

  5

  ;

  data want;

  merge a(in=a) b(in=b);

  by v;

  if a and b then delete;

  run;

Haikuo

Super Contributor
Posts: 349

Re: interview question

Hi ,

Try this..

data a;

input no;

cards;

1

2

3

;

run;

data b;

input no;

cards;

3

4

5

;

run;

data c;

merge a(in=a) b(in=b);

by no;

if a ne b ;

run;

Thanks,

Shiva

Respected Advisor
Posts: 3,124

Re: interview question

Oops, just notice that OP asked in Proc section, so proc sql may be actually needed:

data a;

  input v;

  cards;

  1

  2

  3

  ;

  data b;

  input v;

  cards;

  3

  4

  5

  ;

  proc sql;

  create table want as

  select * from a

  union corr

  select * from b

  except

  (select * from a

  intersect corr

select * from b);

quit;

Haikuo

PROC Star
Posts: 7,360

Re: interview question

Since the subject was interview question, I would think that multiple answers would be preferred.  Thus, I would definitely include interleaving (see, e.g., http://www.sascommunity.org/wiki/Tips:Interleaving ).

Plus, it was never mentioned why 3 wasn't wanted, just that it wasn't wanted and not necessarily just because it was in both datasets.  If it was just because its value was three, I would use an if EID ne 3 statement in the code.

Ask a Question
Discussion stats
  • 4 replies
  • 271 views
  • 1 like
  • 4 in conversation