Ask Your Question
1

In SAS, what is the process for generating a ranking for a defined set of rows?

asked 2021-09-13 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-19 02:00:00 +0000

plato gravatar image

To generate a ranking for a defined set of rows in SAS, you can use the RANK function. The process is as follows:

  1. Sort the data by the variable(s) that you want to rank by.

  2. Create a new variable to hold the rankings.

  3. Use the RANK function to assign a rank to each row based on the sorted variable(s).

For example, suppose you have a data set called sales_data with variables for salesperson name and sales amount. If you want to generate a ranking of the top salespeople based on their sales amount, you could do the following:

SORT sales_data;

DATA salesdata; SET salesdata; RANK = RANK(-sales_amount); RUN;

This code sorts the data by salesamount in descending order, creates a new variable called RANK, and assigns a rank to each row based on the salesamount variable. The - sign before the sales_amount variable in the RANK function tells SAS to rank the data in descending order. The resulting data set will have a new variable called RANK that contains the ranking for each row.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-13 11:00:00 +0000

Seen: 16 times

Last updated: Oct 19 '22