/* HW 5 solutions STAT 541 */ /* Problem 1(a) */ DATA CTL2015more; FILENAME webpage3 URL 'http://people.stat.sc.edu/hitchcock/tennissinglesmore.txt'; INFILE webpage3 DLM='09'X; INPUT Name :$24. Gender $ City :$10. State $ Rating RatingDate MMDDYY10. RatingType $ MatchWins MatchLosses GameWins GameLosses; run; DATA CTL2015more; SET CTL2015more; GameWinPct=100*(GameWins/(GameWins+GameLosses)); MatchWinPct=100*(MatchWins/(MatchWins+MatchLosses)); run; /* Problem 1(b) */ *Lookup table example; data CTL2015array; SET CTL2015more; if rating=2.5 then level=1; if rating=3.0 then level=2; if rating=3.5 then level=3; if rating=4.0 then level=4; if rating=4.5 then level=5; array outrate {1:5, 0:7} _temporary_ (2.0 2.0 2.5 2.5 2.5 2.5 3.0 3.0 2.5 2.5 3.0 3.0 3.0 3.0 3.5 3.5 3.0 3.0 3.5 3.5 3.5 3.5 4.0 4.0 3.5 3.5 4.0 4.0 4.0 4.0 4.5 4.5 4.0 4.0 4.5 4.5 4.5 4.5 5.0 5.0); Rating2016 = outrate(level,MatchWins); run; proc print data=CTL2015array; VAR Name Rating MatchWins Rating2016; run; *Lookup table example done another way; *Done a bit more elegantly, using an informat; PROC FORMAT; invalue ratelev 2.5=1 3.0=2 3.5=3 4.0=4 4.5=5; run; data CTL2015array; SET CTL2015more; array outrate {1:5, 0:7} _temporary_ (2.0 2.0 2.5 2.5 2.5 2.5 3.0 3.0 2.5 2.5 3.0 3.0 3.0 3.0 3.5 3.5 3.0 3.0 3.5 3.5 3.5 3.5 4.0 4.0 3.5 3.5 4.0 4.0 4.0 4.0 4.5 4.5 4.0 4.0 4.5 4.5 4.5 4.5 5.0 5.0); Rating2016 = outrate(input(rating,ratelev.),MatchWins); run; proc print data=CTL2015array; VAR Name Rating MatchWins Rating2016; run; /* Problem 1(c) */ proc format; picture RatingM 4.5='9.99 Top Player' 4.0='9.99 Skilled Player' 3.5='9.99 Intermediate Player' 3.0='9.99 Learning Player' 2.5='9.99 Beginner'; run; PROC PRINT data=CTL2015more; VAR Name Rating; format Rating RatingM.; run; /* Problem 1(d) */ proc format; picture MWPFmt low-50='99.99 % Less Successful Player' 50<-high='099.99 % Successful Player'; run; PROC PRINT data=CTL2015more; VAR Name Rating MatchWinPct; format MatchWinPct MWPFmt.; run; /* Problem 1(e) */ proc format; picture mydate low-high='%B %d, %Y ' (datatype=date); run; PROC PRINT data=CTL2015more; VAR Name RatingDate; format RatingDate mydate.; run; * or can do it without the trailing blanks if you specify the width when applying the format; proc format; picture mydate low-high='%B %d, %Y ' (datatype=date); run; PROC PRINT data=CTL2015more; VAR Name RatingDate; format RatingDate mydate30.; run;