BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jianan_luna
Obsidian | Level 7

When I was analyzing table empT using SQL, the table is as following:

Jianan_luna_0-1600369662485.png

 

I want to find the minimum salary of managers, so I wrote the code as following:

proc sql;
select min(SAL) as min
from cert.emptt
where job='MANAGER';
quit;

I got my answer 2450, but I also want to know the manager's name, thus I wrote code as following:

proc sql;
select min(SAL) as min, ename
from cert.emptt
where job='MANAGER';
quit;

the I got the results:

Jianan_luna_1-1600369769539.png

It shows all manager's name with minimum salary, can you please let me know how can I get the answer of minimum salary with manager's name? Thanks so much

1 ACCEPTED SOLUTION
4 REPLIES 4
Jianan_luna
Obsidian | Level 7

Thanks so much Sir, I got the right answer, but could you please explain why should I use having clause here? I am still confused

Kurt_Bremser
Super User

Maxim 3: Read the Log.

With your original code, you'll find a NOTE about remerging, so we need to prevent that.

To subset based on the result of a SQL summary function, you need HAVING, you cannot use it in a WHERE.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 591 views
  • 3 likes
  • 2 in conversation