Consider this scenario. There is a dataset called "one," in
which the data are collected from
multiple attempts of a test by the same examinees. Each examinee has
unlimited chances to take the test until he/she passes the exam. As a
result, some users may have six attempts, some may have five, some may have
four, and so on. You want to sort the data in the way that examinees with
more number of attempts are shown first. You may say, "A piece of cake. Use
PROC SORT; BY descending attempt user." Try it and I guarantee that you will
not get what you want. This kind of sorting will return something like data
"one_b." You can keep trying sorting different variables in different
order but it will not work. To sort the data properly, you need to take one
more step: PROC SUMMARY. The following code illustrates the procedure: |
Data One
User |
Attempt |
Score |
Alex |
4 |
100 |
Alex |
1 |
99 |
Alex |
2 |
97 |
Alex |
3 |
99 |
Jody |
5 |
99 |
Jody |
6 |
100 |
Jody |
2 |
90 |
Jody |
1 |
87 |
Jody |
4 |
97 |
Jody |
3 |
89 |
Tom |
3 |
100 |
Tom |
1 |
91 |
Tom |
2 |
87 |
|
Data One_B
User |
Attempt |
Score |
Jody |
6 |
100 |
Jody |
5 |
99 |
Alex |
4 |
100 |
Jody |
4 |
97 |
Alex |
3 |
99 |
Jody |
3 |
89 |
Tom |
3 |
100 |
Alex |
2 |
97 |
Jody |
2 |
90 |
Tom |
2 |
87 |
Alex |
1 |
99 |
Jody |
1 |
87 |
Tom |
1 |
91 |
|