BookmarkSubscribeRSS Feed
boin
Obsidian | Level 7

I have two variables

Employee       Manager

Sam               Robert

Robert             Daniel

Greg                Taylor

Taylor              Mark

I want to create a new  variables which should be like this

Twoup     Oneup     Employee

Daniel      Robert     Sam

Please advise ways to get this output.

Kind Regards

Boin


3 REPLIES 3
ballardw
Super User

Proc SQL is one solution. .

Proc Sql;

     create table Supervisors as

     select b.manager as TwoUp, a.Manager as OneUP, a.Employee

     from datasetname as a left join datasetname as b on

          a.manager = b.Employee

    ;

quit;

Haikuo
Onyx | Level 15

Give another hash Smiley Happy,

data have;

input employee :$8. manager:$8.;

cards;

Sam               Robert

Robert             Daniel

Greg                Taylor

Taylor              Mark

;

run;quit;

data want;

length twoup oneup  $ 8;

  if _n_=1 then do;

    if 0 then set have(rename=manager=_m);

    declare hash h(dataset:'have(rename=(manager=_m))');

      h.definekey('employee');

      h.definedata('_m');

      h.definedone();

end;

set have;

  

   if h.find()=0 then do;

      oneup=_m;

        if h.find(key:oneup)=0 then twoup=_m;

      end;

      drop _m manager;

run;


Haikuo

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 665 views
  • 1 like
  • 3 in conversation