/* Example of a Macro with Several Parameters */ data nflplayers; FILENAME webpage URL 'http://people.stat.sc.edu/hitchcock/nfl_season_data.txt'; infile webpage DLM=',' DSD; INPUT idcode $ lastname :$20. firstname :$20. year team $ position $ G GS COMP ATT PassYD PassTD INT rush rushYD rushTD rec recYD recTD; run; /* Get rid of some variables */ /* In particular: */ /* Keeps: PassYD, PassTD, rushYD, rushTD, recYD, recTD */ data selectedstats; set nflplayers (DROP=idcode G GS COMP ATT INT rush rec); run; /* Defining a macro to pick out and print the top few players for a variety of stats, years, positions, or teams */ %MACRO topfew(beginyear=, endyear=, stat=, pos=, teamvalue=, numberlisted=); PROC SORT DATA = selectedstats OUT=statssorted; BY descending &stat; WHERE position = "&pos" AND team = "&teamvalue" AND &beginyear <= year <= &endyear; PROC PRINT data=statssorted (OBS=&numberlisted); VAR firstname lastname team year &stat; TITLE "Top &numberlisted in &stat"; * Note Double Quotes needed; RUN; %MEND topfew; /* Picking Top Two Wide Receivers on Buffalo Bills in Receiving Yards from 1997 */ %topfew(beginyear=1997, endyear=1997, stat=RecYD, pos=wr, teamvalue=buf, numberlisted=2) /* Picking Top Ten Running Backs on Dallas Cowboys in Rushing Yards from 1975 to 2000 */ %topfew(beginyear=1975, endyear=2000, stat=RushYD, pos=rb, teamvalue=dal, numberlisted=10) /* Using default values in the parameters */ %MACRO topfew2(beginyear=, endyear=, stat=, pos=, teamvalue=, numberlisted=10); PROC SORT DATA = selectedstats OUT=statssorted; BY descending &stat; WHERE position = "&pos" AND team = "&teamvalue" AND &beginyear <= year <= &endyear; PROC PRINT data=statssorted (OBS=&numberlisted); VAR firstname lastname team year &stat; TITLE "Top &numberlisted in &stat"; * Note Double Quotes needed; RUN; %MEND topfew2; %topfew2(beginyear=1975, endyear=2000, stat=RushYD, pos=rb, teamvalue=dal)