Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
876 views
in Technique[技术] by (71.8m points)

sas - Sorting Data to get Top Ten Largest Salaries

Hi I am working on a problem where I imported an Excel file to SAS and I need to Sort Salaries of Baseball players and print the top ten largest salaries. I tried to sort it but it is only sorting the first ten observations from my dataset from greatest to smallest and it is not getting the top ten greatest salaries from the entire dataset. This is my code below.

proc sort data=MLB out=salaries_sorted;
format Salary dollar12.3;
by descending Salary descending Year;
proc print data=MLB (obs=10);
run;
question from:https://stackoverflow.com/questions/65948802/sorting-data-to-get-top-ten-largest-salaries

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In this code:

proc sort data=MLB out=salaries_sorted;
format Salary dollar12.3;
by descending Salary descending Year;

You are taking the input dataset MLB, and creating a new sorted table salaries_sorted. You're adding a format there (I'm not sure that works, but even if it does, it's a very unusual place to put it), and then you're telling it how to sort (by salary and year, both descending order).

Then, in this code:

proc print data=MLB (obs=10);
run;

You're printing the top 10 observations of the MLB dataset - but not the sorted dataset.

In order to print the sorted dataset's top 10 rows, you'd need to do this:

proc print data=salaries_sorted(obs=10);
run;

If you don't want the name to change, you can skip the out=salaries_sorted part (and then the MLB dataset will itself be sorted), but it's normally good practice to sort into a new dataset.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...