Quartz | Level 8

## Employees Earning More Than Their Managers

The `Employee` table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

Given the `Employee` table, write data step that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

``````data detail;

input id \$6

name \$8.

salary

ManagerId \$;

datalines;
1  Joe   70000 3
2  Henry 80000 4
3  Sam   60000 .
4  Max   90000 .
;
run;

``````
6 REPLIES 6
Super User

## Re: Employees Earning More Than Their Managers

See if this gets you started. Your data step as posted does not generate the data you think it does.

```data detail;
input id : \$6.
name :\$8.
salary
ManagerId \$
;
datalines;
1  Joe   70000 3
2  Henry 80000 4
3  Sam   60000 .
4  Max   90000 .
;
run;

proc sql;
create table want as
select a.name as employee, b.name as manager, a.salary as empsal, b.salary as managersalary
from detail as a
left join
detail as b
on a.managerid = b.id;
quit;

```
Super User

## Re: Employees Earning More Than Their Managers

What part of the question don't you understand that you need help with? There's a SQL solution above, but the instructions mention data step, so why a data step?

The steps are the same:

1. Merge data with itself

In a data step, you need to rename the variables that are not key ID variables.

2. Flag if Manager is greater than Employee.

Quartz | Level 8

## Re: Employees Earning More Than Their Managers

yes..data step is a must..would you mind tell me the exact code?thanks
Super User

## Re: Employees Earning More Than Their Managers

@Geo- wrote:
yes..data step is a must..would you mind tell me the exact code?thanks

Why data step?

If this is homework then what have you tried?

If it is not homework why do you want what will be a more complicated solution?

Quartz | Level 8

## Re: Employees Earning More Than Their Managers

just some practice that have to be done but means little from the way of using data step.BTW,your sql is wrong in this situation
Super User

## Re: Employees Earning More Than Their Managers

@Geo- wrote:
just some practice that have to be done but means little from the way of using data step.BTW,your sql is wrong in this situation

The SQL isn't wrong, but it's not the full answer to your question, intentionally.

There are two steps to this problem, a merge and a filter (WHERE/IF) operation.

Which step do you not know how to do?

See the video tutorials below for each topic:

Merge data:

https://video.sas.com/detail/video/4572997800001/merging-sas-tables-in-a-data-step

Filter data:

https://video.sas.com/detail/video/4573016761001/filtering-a-sas-table-in-a-data-step

If you still have issues after reviewing these videos (6 minutes roughly in total) post the code you've tried and the log.

@Geo- wrote:
just some practice that have to be done but means little from the way of using data step.BTW,your sql is wrong in this situation

Discussion stats
• 6 replies
• 806 views
• 0 likes
• 3 in conversation