BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

data s ;
length emp $ 10 boss $ 10 ;
input emp $ boss ;
cards ;
harish ashok
ashok siva
siva madhavarao
madhavarao ramaya
;

by using above dataset assign super boss like see below

 

emp              boss                                   superboss


harish            ashok                                 siva
ashok             siva                                    madhavarao                                  
siva                madhavarao                        ramaya
madhavarao   ramaya
;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data s ;
length emp $ 10 boss $ 10 ;
input emp $ boss ;
cards ;
harish ashok
ashok siva
siva madhavarao
madhavarao ramaya
;

data want;
   merge s s(firstobs=2 rename=(boss=superboss) keep=boss);
run;
Ksharp
Super User
data s ;
length emp $ 10 boss $ 10 ;
input emp $ boss ;
cards ;
harish ashok
ashok siva
siva madhavarao
madhavarao ramaya
;

proc sql ;
create table want as
 select a.*	,b.boss as super_boss
  from s as a left join s as b
   on a. boss=b.emp;
quit;
Reeza
Super User
Answer depends on how many levels you need to look up. In the end this is a tree based look up problem. If it's only two levels to define the superboss then it's a trivial double join. If it's more then it's more complicated. PROC BOM will do that though.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 558 views
  • 2 likes
  • 4 in conversation