Create a new variable ,if values in One data set A is equal to values in another data set B then return values from second column in data set b

Reply
Contributor
Posts: 44

Create a new variable ,if values in One data set A is equal to values in another data set B then return values from second column in data set b

  • I Have a data set with the below values

Employee   Manager

sam             Niro

kevin            Daniel

george          Peter

niro                Leo

daniel             David

peter               Leo

david               Leo

another data set

EMPLOYEE

sam

kevin

george

niro

daniel

peter

david

leo

i want the output the output data set to be

employee  Manager

sam            Niro

kevin            Daniel

George       Peter

niro              Leo

daniel           David

peter             Leo

david             Leo

leo



please assist with the above..

Super Contributor
Posts: 543

Re: Create a new variable ,if values in One data set A is equal to values in another data set B then return values from second column in data set b

How about this?;

data one;

input Employee  $ Manager $;

datalines;

sam             Niro

kevin            Daniel

george          Peter

niro                Leo

daniel             David

peter               Leo

david               Leo

;

data two;

input EMPLOYEE $;

datalines;

sam

kevin

george

niro

daniel

peter

david

leo

;

proc sort data = one;by employee;

proc sort data = two;by employee;

data want;

    merge one two;

    by employee;

run;

Good luck,

Anca.

*alternatively;

proc sql;

    create table want as

    select a.manager,b.employee

    from one as a full join two as b

    on a.employee = b.employee;

quit;

Contributor
Posts: 44

Re: Create a new variable ,if values in One data set A is equal to values in another data set B then return values from second column in data set b

Posted in reply to AncaTilea

This is really nice , thank you .. Anca

Ask a Question
Discussion stats
  • 2 replies
  • 186 views
  • 1 like
  • 2 in conversation