BookmarkSubscribeRSS Feed
lyna123
Calcite | Level 5

Hi, 

 

I have a table with 45 stores and their total sales. I need to find the stores with the 3 worst sales. 

I know I can sort the values ascending and then deduct the last 3 but I wonder if there is a way to find the last 3 directly. when I use de min, its only for one value, how do we do to find the 3 min?

 

Thank you, 

Lyna

3 REPLIES 3
novinosrin
Tourmaline | Level 20

How about proc rank?

 

You could filter the ranked variable to your needs. 

ballardw
Super User

Any particular reason why Proc SQL must be used? Almost anything that involves order is more difficult in SQL. Did you mean to say sort ASCENDING and keep the first three results (obs=3)?

 

Proc Means can do this depending on how many other variables need to be in the output in a single step.

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
  • 1021 views
  • 0 likes
  • 4 in conversation