/*****************************************************/ /* STAT 330, Fall 2011 */ /* Homework 11 */ /*****************************************************/ options nocenter nodate nonumber pageno=1 pagesize=55 linesize=90; %let path = C:\Classes\STAT 330\2011-4\Homework; /* 11.1.1 */ %let lastEvent = 4; %let user = Ulric Lund; %let date = 11/30/2011; ods pdf file="c:\temp\ASP &lastEvent Events.pdf"; filename readASP dde "Excel|&path\[ASP Nov 2011.xlsx]ASP Rankings Nov 2011!R2C1:R41C17"; data asp2011; infile readASP notab dlm='09'x dsd; informat name $30. country $3. char1-char11 $3. earn2011 earnCareer comma8.; input rank name country char1-char11 totalPts earn2011 earnCareer; run; data recode; set asp2011; array charPlaces $ char1-char11; array numPlaces place1-place11; do over charPlaces; if charPlaces = "-" then numPlaces = -9; else if charPlaces = "INJ" then numPlaces = -99; else numPlaces = input(charPlaces, 3.); end; drop char1-char11; run; data addPoints; set recode; array numPlaces place1-place11; array points points1-points11; do over numPlaces; if numPlaces = 1 then points = 10000; if numPlaces = 2 then points = 8000; if numPlaces = 3 then points = 6500; if numPlaces = 5 then points = 5200; if numPlaces = 9 then points = 4000; if numPlaces = 13 then points = 1750; if numPlaces = 25 then points = 500; if numPlaces = -9 then points = 0; if numPlaces = -99 then points = 500; end; run; proc sort data=addPoints out=preCalc; by name; run; /* What follows is my solution to dropping the 2 lowest: I used PROC TRANSPOSE and SORT to get scores ranked from highest to lowest. There is another solution using the CALL SORTN routine or function that I saw at least one of you use. */ proc transpose data=preCalc out=calcTotal (drop=_name_); var points1 - points&lastEvent; by name; /* For each surfer, get one record per event. Get data into long form. */ run; proc sort data=calcTotal; by name descending col1; /* For each surfer, get the events in order of high to low points */ run; proc transpose data=calcTotal out=calcTotal; var col1; by name; /* Get data back into short form, where there is only one record per surfer. But now, you have the 11 events points going across as variables from high to low. */ run; data calcTotal; set calcTotal; if &lastEvent = 10 then SASpts = sum(of col1 - col9); /* Take the 9 best */ else if &lastEvent = 11 then SASpts = sum(of col1 - col9); /* Take the 9 best; could have combined with above */ else SASpts = sum(of col1 - col&lastEvent); /* Take them all */ run; proc sort data=calcTotal; by name; run; data printData; merge preCalc calcTotal; by name; keep name country totalPts SASpts place1-place&lastEvent points1-points&lastEvent; run; proc sort data=printData; by descending SASpts name; run; proc format; value places -9=" Absent" -99="Injured"; run; title font=times bold "ASP Leaders Through Event #&lastEvent"; footnote font=times height=0.75 bold "Executed by &user, on &date"; proc print data=printData split="#" noobs width=full; var name country place1 - place&lastEvent SASPts; format place1 - place&lastEvent places.; label place1="Event 1#" place2="Event 2#" place3="Event 3#" place4="Event 4#" place5="Event 5#" place6="Event 6#" place7="Event 7#" place8="Event 8#" place9="Event 9#" place10="Event 10#" place11="Event 11#" name="Name" country="Country" sasPts="Total Pts"; run; ods pdf close;