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

Hi Forum,

I'm using SAS EG 5.1 (64 bit) on Windows 7.

I'm trying to Rank some Order Dates & Customer numbers.

I've sorted the dates in the previous Query Builder & then added a Ranking Task.

I've added the 'Order Dates' to the 'Columns to rank' area of the Rank wizard & 'Customer Number' to the 'Rank By' area.

I then select 'Descending' in the 'Rank By' fields sort order & run the task.

No matter what I do, it always sorts in Ascending order.

I've tried sorting the previous node the other way but no use.

What am I missing here?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The Rank Data task is used to compute a rank across one or more numeric variables in the input data.  Usually you would use this to assign an ordinal rank to a quantitative variable, such as "Sales amount" or "Units Sold".  You would not use it to rank time series data (like Dates) or ID variables (like a Customer ID Number).

The "Rank By" role is for grouping purposes, not for sorting.  For example, if you wanted to compute the rank for Customer Sales in each Country, Customer Sales would be the Rank variable and Country would be the Rank By.  The output would include rank output (1, 2, 3, and so on) for each value of Country within your data set.

The output data is not sorted by rank.  If you need the data sorted, you can feed the output data set into a Sort Data task or the Query Builder.

I'm not sure what your ultimate goal is, but you might be interested in this sample for creating a Top N report in SAS.

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

3 REPLIES 3
Oscarboots
Quartz | Level 8

Can anyone suggest any tutorials on how to use the Rank Task so I can find what I'm doing wrong?

Thanks again.Smiley Happy

ChrisHemedinger
Community Manager

The Rank Data task is used to compute a rank across one or more numeric variables in the input data.  Usually you would use this to assign an ordinal rank to a quantitative variable, such as "Sales amount" or "Units Sold".  You would not use it to rank time series data (like Dates) or ID variables (like a Customer ID Number).

The "Rank By" role is for grouping purposes, not for sorting.  For example, if you wanted to compute the rank for Customer Sales in each Country, Customer Sales would be the Rank variable and Country would be the Rank By.  The output would include rank output (1, 2, 3, and so on) for each value of Country within your data set.

The output data is not sorted by rank.  If you need the data sorted, you can feed the output data set into a Sort Data task or the Query Builder.

I'm not sure what your ultimate goal is, but you might be interested in this sample for creating a Top N report in SAS.

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Oscarboots
Quartz | Level 8

Thanks Chris,

In the end I got around it by coding 'ROW_NUMBER() (Partition by...).

Cheers

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1688 views
  • 0 likes
  • 2 in conversation