SAS OUTPUT (CLICK IMAGE TO VIEW LARGER VERSION)
Inspired by a cheesy video showing all of the US Presidents' heights that Business Insider posted Saturday, here's my cheesy SAS ODS Graphics take on All-the-Presidents'-Heights. Btw, if you ever need kludgy-but-it-works VBA code to save images in an Excel worksheet into separate .png files - e.g., after you've cut-and-pasted a bunch of 'em into a worksheet from a web page - code's below. No warranties expressed or implied, as they say. 🙂
SAS CODE
*==> Fun w/SAS ODS Graphics: All the Presidents' Heights
Photos from en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States
Heights from en.wikipedia.org/wiki/Heights_of_presidents_and_presidential_candidates_of_the_United_States;
proc import datafile='/folders/myfolders/Presidents/45Presidents.csv' dbms=csv out=Presidents replace;
%let datasymbols=; * Map 45 Presidents to 45 Wikipedia images;
%macro gensymbols;
%do p=1 %to 45;
symbolimage name=symP%sysfunc(putn(&p,z2)) /* Offset cropped images so top of heads approximate height */
image="/folders/myfolders/Presidents/President%sysfunc(putn(&p,z2)).png" / voffset=-.5;
%let datasymbols=&datasymbols symP%sysfunc(putn(&p,z2));
%end;
%mend;
* Create composite needle/scatter/text plot!;
ods listing image_dpi=80 gpath='/folders/myfolders';
ods graphics on / reset antialias width=24in height=5in attrpriority=none imagename="PresidentHeight";
proc sgplot data=Presidents noborder noautolegend;
%gensymbols;
styleattrs datasymbols=(&datasymbols);
xaxis display=none offsetmin=.001 offsetmax=.001 min=0 max=46;
yaxis display=none offsetmin=.001 offsetmax=.001;
needle x=num y=heightcm / lineattrs=(thickness=2pt color=black);
scatter x=Num y=heightcm / group=num markerattrs=(size=36pt);
text x=num y=heightcm text=heightin / position=top textattrs=(color=black size=8pt) strip;
xaxistable lastname / nolabel valueattrs=(color=black size=8pt) position=top location=inside;
Footnote height=14pt bold "ALL THE PRESIDENTS' HEIGHTS";
HEIGHT DATA
Num,President,HeightIn,HeightCm,LastName 1,George Washington,"6' 2""",188,Washington 2,John Adams,"5' 7""",170,Adams 3,Thomas Jefferson,"6' 2½""""",189,Jefferson 4,James Madison,"5' 4""",163,Madison 5,James Monroe,"6' 0""",183,Monroe 6,John Quincy Adams,"5' 7½""""",171,Adams 7,Andrew Jackson,"6' 1""",185,Jackson 8,Martin VanBuren,"5' 6""",168,VanBuren 9,William Henry Harrison,"5' 8""",173,Harrison 10,John Tyler,"6' 0""",183,Tyler 11,James K. Polk,"5' 8""",173,Polk 12,Zachary Taylor,"5' 8""",173,Taylor 13,Millard Fillmore,"5' 9""",175,Fillmore 14,Franklin Pierce,"5' 10""",178,Pierce 15,James Buchanan,"6' 0""",183,Buchanan 16,Abraham Lincoln,"6' 4""",193,Lincoln 17,Andrew Johnson,"5' 10""",178,Johnson 18,Ulysses S. Grant,"5' 8""",173,Grant 19,Rutherford B. Hayes,"5' 8½""""",174,Hayes 20,James A. Garfield,"6' 0""",183,Garfield 21,Chester A. Arthur,"6' 2""",188,Arthur 22,Grover Cleveland,"5' 11""",180,Cleveland 23,Benjamin Harrison,"5' 6""",168,Harrison 24,Grover Cleveland,"5' 11""",180,Cleveland 25,William McKinley,"5' 7""",170,McKinley 26,Theodore Roosevelt,"5' 10""",178,Roosevelt 27,William Howard Taft,"5' 11½""""",182,Taft 28,Woodrow Wilson,"5' 11""",180,Wilson 29,Warren G. Harding,"6' 0""",183,Harding 30,Calvin Coolidge,"5' 10""",178,Coolidge 31,Herbert Hoover,"5' 11½""""",182,Hoover 32,Franklin D. Roosevelt,"6' 2""",188,Roosevelt 33,Harry S. Truman,"5' 9""",175,Truman 34,Dwight D. Eisenhower,"5' 10½""""",179,Eisenhower 35,John F. Kennedy,"6' 0""",183,Kennedy 36,Lyndon B. Johnson,"6' 3""",191,Johnson 37,Richard Nixon,"5' 11""",180,Nixon 38,Gerald Ford,"6' 0""",183,Ford 39,Jimmy Carter,"5' 9½""""",177,Carter 40,Ronald Reagan,"6' 1""",185,Reagan 41,George H. W. Bush,"6' 2""",188,Bush 42,Bill Clinton,"6' 2""",188,Clinton 43,George W. Bush,"5' 11½""""",182,Bush 44,Barack Obama,"6' 1""",185,Obama 45,Donald Trump,"6' 2""",188,Trump
VBA CODE (SAVE IMAGES IN EXCEL SHEET TO .PNG FILES)
Sub ExportPresidentPictures() ' Exports cropped President thumbnails in active worsheet as .png files, adapted from: ' http://stackoverflow.com/questions/18232987/export-pictures-from-excel-file-into-jpg-using-vba ' A kludge, but it works! pnum = 0 For Each p In ActiveSheet.Pictures pnum = pnum + 1 Debug.Print p.Name, Cells(p.TopLeftCell.Row, 1), p.Height, p.Width Charts.Add ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" Selection.Border.LineStyle = 0 MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2) ActiveSheet.ChartObjects(1).Width = p.Width ActiveSheet.ChartObjects(1).Height = p.Height p.Copy ActiveSheet.ChartObjects(1).Activate ActiveChart.Paste ActiveChart.Export Filename:="C:\Users\tedco\Documents\SASUniversityEdition\myfolders\Presidents\President" & Format(pnum, "00") & ".png", FilterName:="png" ActiveSheet.Shapes(MyChart).Delete Next p End Sub
SAMPLE VBA OUTPUT
Wow! That's great. Now let's join it with max approval rating!
I think a comparison with average male (since to date all of the presidents have been male) height would be interesting.
So Lincoln stands above all other presidents. How appropriate! Thanks for a fun example.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.