BookmarkSubscribeRSS Feed
SASAlex101
Quartz | Level 8

I have the following Dataset:

 

data WORK.have;
Length EmpName $100. ManagerName $100.;
Infile datalines delimiter='#';
input EmpID ManagerID EmpName $ ManagerName $;
datalines;
1#4#WALTER WHITE#GUS FRING
2#1#JESSE PINKMAN#WALTER WHITE
3#1#SAUL GOODNAM#WALTER WHITE
4#5#GUS FRING#ELADIO VUENTE
5#5#ELADIO VUENTE#ELADIO VUENTE
6#2#SKINNY PETE#JESSE PINKMAN
7#2#COMBO#JESSE PINKMAN
;
run;

Is there a quick macro script that will find all children (if any) from the table based on EmpID / ManagerID hierarchy and produce the following output?:

data WORK.Want;
Length EmpName $100. ManagerName $100.;
Infile datalines delimiter='#';
input EmpName $ ManagerName $ Level;
datalines;
WALTER WHITE#WALTER WHITE#1
JESSE PINKMAN#WALTER WHITE#2
SKINNY PETE#WALTER WHITE#3
COMBO#WALTER WHITE#3
SAUL GOODNAM#WALTER WHITE#2
JESSE PINKMAN#JESSE PINKMAN#1
SKINNY PETE#JESSE PINKMAN#2
COMBO#JESSE PINKMAN#2
SAUL GOODNAM#SAUL GOODNAM#1
GUS FRING#GUS FRING#1
WALTER WHITE#GUS FRING#2
JESSE PINKMAN#GUS FRING#3
SKINNY PETE#GUS FRING#4
COMBO#GUS FRING#4
SAUL GOODNAM#GUS FRING#3
ELADIO VUENTE#ELADIO VUENTE#1
GUS FRING#ELADIO VUENTE#2
WALTER WHITE#ELADIO VUENTE#3
JESSE PINKMAN#ELADIO VUENTE#4
SKINNY PETE#ELADIO VUENTE#5
COMBO#ELADIO VUENTE#5
SAUL GOODNAM#ELADIO VUENTE#4
SKINNY PETE#SKINNY PETE#1
COMBO#COMBO#1

;
run;

Essentially expanding it out to a simple lookup table. I'm somewhat new to macros do I'm not too sure where to begin. 

 

Thanks;

 

3 REPLIES 3
Reeza
Super User
What is the rationale behind the macro requirement? This is usually a hash solution, not macros so curious as to the logic behind that requirement.
SASAlex101
Quartz | Level 8
I would be in favor of seeing the "Hash" solution. I mentioned macros because I am ignorantly assuming there isnt't any other clever way to solve the problem in SaS.
AlanC
Barite | Level 11
Macros are merely a way to generate regular SAS code. They arent anything different or special. I would suggest using a RETAIN statement.
https://github.com/savian-net

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 903 views
  • 2 likes
  • 3 in conversation