BookmarkSubscribeRSS Feed
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Within DivisionsWithin Divisions

Across DivisionsAcross Divisions

 

With the regular NFL season wrapping up, are you ready for some SAS ODS Graphics football? A bit oversimplified on the rankings (left as an exercise for you NFL tiebreaking procedures experts!) but here's a SAS ODS Graphics 100% Win-Loss-Tie Bar Chart take on the latest intra and inter-divisional NFL Standings using SGPANEL and SGPLOT.

 

* Fun With SAS ODS Graphics: A Bar Chart Look at Intra and Inter-Conference NFL Standings
  Data source: google.com/search?q=nfl+standings;
                                                                * Import data from Excel;
proc import datafile='/home/ted.conway/NFLstandings20241219.xlsx' dbms=xlsx 
            out=nflstats(rename=(c=TEAM d=W_CHAR e=L_CHAR f=T_CHAR)) replace;
getnames=no;
                                                                * Cleanup and eshape data for charting;
data nflstats2chart(keep=TEAM_CONF_DIV CONF_DIV TEAM pct wlt wlt_order games w l t);
set nflstats;
length CONF_DIV $ 25.; retain CONF_DIV;                         * Get conference/division from column A and retain it; 
if a=:'NFC' or a=:'AFC' then CONF_DIV=A;
if a=:'NFC' or a=:'AFC' or team in ('','Team') then delete;     * Only output rows with standings;
TEAM_CONF_DIV=catt(TEAM, ' (', CONF_DIV, ')');                  * Create composite column for ranking across conferences/divisions;
w=input(w_char,best.);                                          * Convert wins/losses/ties to numeric;
l=input(l_char,best.);
t=input(t_char,best.);
pct=w/(w+l+t);                                                  * Calc winning percentage for ranking;
wlt='W'; wlt_order=1; games=W; output;                          * Create 1 row for each type (wins/losses/ties);
wlt='L'; wlt_order=2; games=L; output; 
wlt='T'; wlt_order=3; games=T; output;

%SGANNO;                                                        * Create annotation dataset with NFL logo, location using SAS macros;         
data nflimg;                                                    * Source: en.wikipedia.org/wiki/File:National_Football_League_logo.svg;
%SGIMAGE (image="/home/ted.conway/National_Football_League_logo.svg.png",drawspace="GRAPHPERCENT",x1=94.4,y1=6,height=10,heightunit="PERCENT",anchor="bottomright");                                                            
                                                                * Rank teams by winning % within divisions;
proc sort data=nflstats2chart; by conf_div descending pct team wlt_order;
                                                                * SGPANEL bar chart of standings within conferences;
ods graphics / reset height=7in width=9in noborder imagefmt=svg;
proc sgpanel data=nflstats2chart noautolegend pad=(left=.2in right=.2in) pctlevel=group sganno=nflimg;
styleattrs datacolors=(green red lightgrey);                    * Colors for wins/losses/ties;
panelby CONF_DIV / headerbackcolor=white columns=1 layout=rowlattice uniscale=column onepanel noheaderborder noborder rowheaderpos=left novarname spacing=3;
hbar team / response=games group=WLT barwidth=1 stat=percent dataskin=crisp grouporder=data fill seglabel seglabelattrs=(color=white weight=bold);
colaxis values=(0 to 1 by .1) valuesformat=percent6. display=(nolabel noline) refticks=(values) offsetmin=.02;
rowaxis discreteorder=data display=(nolabel noticks noline) offsetmin=.15 offsetmax=.15 labelattrs=(weight=bold size=12pt); 
rowaxistable games / classorder=data position=left valueattrs=(size=8.5pt) pad=0;
refline (.1 to 1 by .1) / axis=x label="";     

%SGANNO;                                                        * Create annotation dataset with NFL logo, location using SAS macros; 
data nflimg;                                                    * Source: en.wikipedia.org/wiki/File:National_Football_League_logo.svg;
%SGIMAGE (image="/home/ted.conway/National_Football_League_logo.svg.png",drawspace="GRAPHPERCENT",x1=94.6,y1=7.6,height=10,heightunit="PERCENT",anchor="bottomright"); 
                                                                * Rank teams by winning % across divisions;
proc sort data=nflstats2chart; by descending pct team wlt_order;
                                                                * SGPLOT bar chart of standings across conferences;
proc sgplot data=nflstats2chart(drop=pct) noborder noautolegend pad=(left=.2in right=.2in) pctlevel=group sganno=nflimg;;
styleattrs datacolors=(green red lightgrey);                    * Colors for wins/losses/ties;
hbar TEAM_CONF_DIV / response=games dataskin=crisp stat=percent group=WLT barwidth=1 grouporder=data seglabel seglabelattrs=(color=white weight=bold);
xaxis values=(0 to 1 by .1) valuesformat=percent6. display=(nolabel noline) refticks=(values) offsetmin=.02;
yaxis discreteorder=data display=(noline noticks nolabel) labelattrs=(weight=bold size=11pt);      
refline (.1 to 1 by .1) / axis=x label="";
yaxistable games / classorder=data position=left location=inside valueattrs=(size=8.5pt);
run;

 

Sample Input DataSample Input Data

1 REPLY 1
ChrisHemedinger
Community Manager

Go Bills!

 

PXL_20241213_235832504.jpg

 

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2025 views
  • 7 likes
  • 2 in conversation