data olympics;
infile datalines dlm='/';
input Team/NOC:& $26. Gold 29 Silver 31 Bronze 34;
datalines;
United States of America 8 3 8
Japan 8 2 3
People's Republic of China 7 5 7
ROC 5 7 3
Great Britain 4 5 1
Australia 3 1 3
Republic of Korea 3 0 4
Kosovo 2 0 0
Italy 1 4 4
Canada 1 3 1
France 1 2 2
Hungary 1 1 0
Tunisia 1 1 0
Croatia 1 0 1
Slovenia 1 0 1
Austria 1 0 0
Bermuda 1 0 0
Ecuador 1 0 0
Hong Kong, China 1 0 0
Islamic Republic of Iran 1 0 0
Norway 1 0 0
Philippines 1 0 0
Thailand 1 0 0
Uzbekistan 1 0 0
Netherlands 0 3 0
Brazil 0 2 2
Chinese Taipei 0 2 2
Georgia 0 2 0
Czech Republic 0 1 1
Spain 0 1 1
Indonesia 0 1 1
Serbia 0 1 1
Switzerland 0 1 1
Belgium 0 1 0
Bulgaria 0 1 0
Colombia 0 1 0
Denmark 0 1 0
India 0 1 0
Jordan 0 1 0
Romania 0 1 0
South Africa 0 1 0
Germany 0 0 3
Kazakhstan 0 0 3
Ukraine 0 0 3
Egypt 0 0 2
Mongolia 0 0 2
Turkey 0 0 2
Côte d'Ivoire 0 0 1
Estonia 0 0 1
Israel 0 0 1
Kuwait 0 0 1
Mexico 0 0 1
New Zealand 0 0 1
;
run;
proc rank data=olympics_ranks out=ran ties=low;
var silver ;
ranks rankposition;
by Team/NOC notsorted;
run;
Required Output:
Rank | Team/NOC | Gold | Silver | Bronze | Total | Rank by Total |
1 | United States of America | 8 | 3 | 8 | 19 | 1 |
2 | Japan | 8 | 2 | 3 | 13 | 4 |
3 | People's Republic of China | 7 | 5 | 7 | 19 | 1 |
4 | ROC | 5 | 7 | 3 | 15 | 3 |
5 | Great Britain | 4 | 5 | 1 | 10 | 5 |
6 | Australia | 3 | 1 | 3 | 7 | 7 |
7 | Republic of Korea | 3 | 0 | 4 | 7 | 7 |
8 | Kosovo | 2 | 0 | 0 | 2 | 17 |
9 | Italy | 1 | 4 | 4 | 9 | 6 |
10 | Canada | 1 | 3 | 1 | 5 | 9 |
11 | France | 1 | 2 | 2 | 5 | 9 |
12 | Hungary | 1 | 1 | 0 | 2 | 17 |
12 | Tunisia | 1 | 1 | 0 | 2 | 17 |
14 | Croatia | 1 | 0 | 1 | 2 | 17 |
14 | Slovenia | 1 | 0 | 1 | 2 | 17 |
16 | Austria | 1 | 0 | 0 | 1 | 31 |
16 | Bermuda | 1 | 0 | 0 | 1 | 31 |
16 | Ecuador | 1 | 0 | 0 | 1 | 31 |
16 | Hong Kong, China | 1 | 0 | 0 | 1 | 31 |
16 | Islamic Republic of Iran | 1 | 0 | 0 | 1 | 31 |
16 | Norway | 1 | 0 | 0 | 1 | 31 |
16 | Philippines | 1 | 0 | 0 | 1 | 31 |
16 | Thailand | 1 | 0 | 0 | 1 | 31 |
16 | Uzbekistan | 1 | 0 | 0 | 1 | 31 |
25 | Netherlands | 0 | 3 | 0 | 3 | 13 |
26 | Brazil | 0 | 2 | 2 | 4 | 11 |
26 | Chinese Taipei | 0 | 2 | 2 | 4 | 11 |
28 | Georgia | 0 | 2 | 0 | 2 | 17 |
29 | Czech Republic | 0 | 1 | 1 | 2 | 17 |
29 | Spain | 0 | 1 | 1 | 2 | 17 |
29 | Indonesia | 0 | 1 | 1 | 2 | 17 |
29 | Serbia | 0 | 1 | 1 | 2 | 17 |
29 | Switzerland | 0 | 1 | 1 | 2 | 17 |
34 | Belgium | 0 | 1 | 0 | 1 | 31 |
34 | Bulgaria | 0 | 1 | 0 | 1 | 31 |
34 | Colombia | 0 | 1 | 0 | 1 | 31 |
34 | Denmark | 0 | 1 | 0 | 1 | 31 |
34 | India | 0 | 1 | 0 | 1 | 31 |
34 | Jordan | 0 | 1 | 0 | 1 | 31 |
34 | Romania | 0 | 1 | 0 | 1 | 31 |
34 | South Africa | 0 | 1 | 0 | 1 | 31 |
42 | Germany | 0 | 0 | 3 | 3 | 13 |
42 | Kazakhstan | 0 | 0 | 3 | 3 | 13 |
42 | Ukraine | 0 | 0 | 3 | 3 | 13 |
45 | Egypt | 0 | 0 | 2 | 2 | 17 |
45 | Mongolia | 0 | 0 | 2 | 2 | 17 |
45 | Turkey | 0 | 0 | 2 | 2 | 17 |
48 | Côte d'Ivoire | 0 | 0 | 1 | 1 | 31 |
48 | Estonia | 0 | 0 | 1 | 1 | 31 |
48 | Israel | 0 | 0 | 1 | 1 | 31 |
48 | Kuwait | 0 | 0 | 1 | 1 | 31 |
48 | Mexico | 0 | 0 | 1 | 1 | 31 |
48 | New Zealand | 0 | 0 | 1 | 1 | 31 |
What are you asking? Is the code that you have posted not working? If so, can you post the contents of the log using the icon shown in the screen capture, below?
Jim
For starters, you need to correct the Datastep, the one with Datalines in it. The delimiter needs to change from a '/' (forward slash) to '09'x (tab).
Also the numbers that follow the counts need to be eliminated.
input Team_NOC:& $26. Gold 30 Silver 33 Bronze 37;
Such numbers typically are used with fixed position data. You have delimited data. I added "missover" which I typically find to be a good practice -- but it's not strictly speaking necessary here.
In addition, Team/NOC is not a valid SAS V7 name. I changed it to Team_NOC.
Jim
Corrected code:
data olympics;
infile datalines
dsd dlm='09'x
missover
;
/*input Team_NOC:& $26. Gold 30 Silver 33 Bronze 37;*/
input Team_NOC:& $26. Gold Silver Bronze;
*---+----1----+----2----+----3----+----4;
datalines;
United States of America 8 3 8
Japan 8 2 3
People's Republic of China 7 5 7
ROC 5 7 3
Great Britain 4 5 1
Australia 3 1 3
Republic of Korea 3 0 4
Kosovo 2 0 0
Italy 1 4 4
Canada 1 3 1
France 1 2 2
Hungary 1 1 0
Tunisia 1 1 0
Croatia 1 0 1
Slovenia 1 0 1
Austria 1 0 0
Bermuda 1 0 0
Ecuador 1 0 0
Hong Kong, China 1 0 0
Islamic Republic of Iran 1 0 0
Norway 1 0 0
Philippines 1 0 0
Thailand 1 0 0
Uzbekistan 1 0 0
Netherlands 0 3 0
Brazil 0 2 2
Chinese Taipei 0 2 2
Georgia 0 2 0
Czech Republic 0 1 1
Spain 0 1 1
Indonesia 0 1 1
Serbia 0 1 1
Switzerland 0 1 1
Belgium 0 1 0
Bulgaria 0 1 0
Colombia 0 1 0
Denmark 0 1 0
India 0 1 0
Jordan 0 1 0
Romania 0 1 0
South Africa 0 1 0
Germany 0 0 3
Kazakhstan 0 0 3
Ukraine 0 0 3
Egypt 0 0 2
Mongolia 0 0 2
Turkey 0 0 2
Côte d'Ivoire 0 0 1
Estonia 0 0 1
Israel 0 0 1
Kuwait 0 0 1
Mexico 0 0 1
New Zealand 0 0 1
;
run;
This identical question has come up here:
https://communities.sas.com/t5/SAS-Programming/Rank-by-total/m-p/757123
Are you by any means an acquaintance of @BrahmanandaRao ?
Please do not post your data using data step code that doesn't work. You can run the DATA step and see if it works. Get the data step code to work properly, and then we can help you. (Although as pointed out, the answer is already provided elsewhere, you still ought to make sure your data step code works before you post it, there's really no excuse for posting DATA step code to provide your data that doesn't work)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.