BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8
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:

RankTeam/NOCGoldSilverBronzeTotalRank by Total

1

United States of America

838191
2

Japan

823134
3

People's Republic of China

757191
4

ROC

573153
5

Great Britain

451105
6

Australia

31377
7

Republic of Korea

30477
8

Kosovo

200217
9

Italy

14496
10

Canada

13159
11

France

12259
12

Hungary

110217
12

Tunisia

110217
14

Croatia

101217
14

Slovenia

101217
16

Austria

100131
16

Bermuda

100131
16

Ecuador

100131
16

Hong Kong, China

100131
16

Islamic Republic of Iran

100131
16

Norway

100131
16

Philippines

100131
16

Thailand

100131
16

Uzbekistan

100131
25

Netherlands

030313
26

Brazil

022411
26

Chinese Taipei

022411
28

Georgia

020217
29

Czech Republic

011217
29

Spain

011217
29

Indonesia

011217
29

Serbia

011217
29

Switzerland

011217
34

Belgium

010131
34

Bulgaria

010131
34

Colombia

010131
34

Denmark

010131
34

India

010131
34

Jordan

010131
34

Romania

010131
34

South Africa

010131
42

Germany

003313
42

Kazakhstan

003313
42

Ukraine

003313
45

Egypt

002217
45

Mongolia

002217
45

Turkey

002217
48

Côte d'Ivoire

001131
48

Estonia

001131
48

Israel

001131
48

Kuwait

001131
48

Mexico

001131
48

New Zealand

001131
4 REPLIES 4
jimbarbour
Meteorite | Level 14

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?

jimbarbour_0-1627493454334.png

Jim

jimbarbour
Meteorite | Level 14

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;

 

PaigeMiller
Diamond | Level 26

@pavank 

 

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)

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 536 views
  • 2 likes
  • 4 in conversation