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

PresidentAges.png

 

At home waiting for the Comcast installer today (75Mbps, Internet here I come!), so thought I'd take a crack at Rick Wicklin's visualize-the-ages-of-US-presidents challenge. Try as I might, I'm afraid Rick wins this ODS Graphics throwdown with his elegant viz, but thought I'd post my stab at a Gantt chart-like solution anyway (which I "adapted" from Sanjay Matange's The HIGHLOW Plot). Wait'll next year, as we Cubs fans (used to!) say. Smiley Happy

 

CODE (uses RW's Presidents SAS dataset)

* Gantt-chart like take on Rick Wicklin's Presidential ages vector chart;

title;
proc format;                             * Kludge since Trump's term TBD;
picture trump 74.1-74.9="?" other='99.9';

data presidents2;
set presidents;
if AgeAtEndDate=. then AgeAtEndDate=AgeAtInauguration+4; * Default to 4-year term;
format AgeAtInauguration AgeAtEndDate trump.;
label InaugurationDate="Inaugurated" PresidencyEndDate="End Date";

ods graphics on / imagemap height=11.25in width=11.25in;
proc sgplot data=presidents2 noautolegend;
highlow y=President low=AgeAtInauguration high=AgeAtEndDate /
         lowlabel=AgeAtInauguration highlabel=AgeAtEndDate lineattrs=(thickness=4pt);
yaxis grid reverse display=(nolabel noticks); 
yaxistable InaugurationDate PresidencyEndDate;
xaxis grid values=(40 to 80 by 5) valuesformat=z2. 
      label="Age of US Presidents at Beginning and End of Term";
run;
3 REPLIES 3
MichelleHomes
Meteorite | Level 14

Nice work @tc! Pleased to see you took up the challenge Smiley Wink

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Oops - didn't notice that Grover Cleveland had two terms, which threw a monkey wrench into my inauguration and term end dates (nice to see HIGHLOW handles the multiple line segments though!). Added President # tie-breaker - revised code, output below.

 

CODE

title;
proc format;                             * Kludge since Trump's term TBD;
picture trump 74.1-74.9="?" other='99.9';

data presidents2;
set presidents;
if AgeAtEndDate=. then AgeAtEndDate=AgeAtInauguration+4; * Default to 4-year term;
format AgeAtInauguration AgeAtEndDate trump. InaugurationDate PresidencyEndDate yymmddd10.;
label InaugurationDate="Inaugurated" PresidencyEndDate="End Date";

ods graphics on / imagemap height=11.25in width=11.25in;
proc sgplot data=presidents2 noautolegend;
highlow y=n low=AgeAtInauguration high=AgeAtEndDate /
        lowlabel=AgeAtInauguration highlabel=AgeAtEndDate lineattrs=(thickness=4pt);
yaxis grid reverse display=(nolabel noticks) type=discrete valueattrs=(size=8pt); 
yaxistable president / position=left valueattrs=(size=8pt) nolabel;
yaxistable InaugurationDate PresidencyEndDate / valueattrs=(size=8pt) labelattrs=(size=8pt);
xaxis grid values=(40 to 80 by 5) valuesformat=z2. valueattrs=(size=8pt)
      label="Age of US Presidents at Beginning and End of Term";
run

CHART

PresidentAgesV2.png

BranumMartin
Calcite | Level 5

Rick is awesome, but this chart is far cleaner, easier to read, and more informative. Congrats!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 2019 views
  • 5 likes
  • 3 in conversation