Example adapted from Rick Wicklin's blog
Zodiac SAS format from Chris Hemedinger's blog
/* Program to accompany
Wicklin, R., "Visualize the ages of US presidents"
Published 14Nov2016 at The DO Loop blog
http://blogs.sas.com/content/iml/2016/11/14/viz-age-us-president.html
Data from
https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States_by_age
*/
data Presidents;
input @1 N 2.
@4 President $23.
@28 BirthDate anydtdte12.
@44 InaugurationDate anydtdte12.
@60 PresidencyEndDate anydtdte12.
;
/* use the YRDIF function to compute ages */
AgeAtInauguration = yrdif(BirthDate, InaugurationDate, 'ACT/ACT');
AgeAtEndDate = yrdif(BirthDate, PresidencyEndDate, 'ACT/ACT');
format BirthDate InaugurationDate PresidencyEndDate DATE10.;
label AgeAtInauguration="Age at First Inauguration"
AgeAtEndDate="Age at End of Term"
InaugurationDate="Inauguration Date";
/* get last names to use as labels */
LastName = scan(President, countw(President));
if AgeAtInauguration<=50 | AgeAtInauguration>=65 then
Label= LastName;
else Label=" ";
datalines;
1 George Washington Feb 22, 1732 Apr 30, 1789 Mar 4, 1797
2 John Adams Oct 30, 1735 Mar 4, 1797 Mar 4, 1801
3 Thomas Jefferson Apr 13, 1743 Mar 4, 1801 Mar 4, 1809
4 James Madison Mar 16, 1751 Mar 4, 1809 Mar 4, 1817
5 James Monroe Apr 28, 1758 Mar 4, 1817 Mar 4, 1825
6 John Q. Adams Jul 11, 1767 Mar 4, 1825 Mar 4, 1829
7 Andrew Jackson Mar 15, 1767 Mar 4, 1829 Mar 4, 1837
8 Martin Van Buren Dec 5, 1782 Mar 4, 1837 Mar 4, 1841
9 William H. Harrison Feb 9, 1773 Mar 4, 1841 Apr 4, 1841
10 John Tyler Mar 29, 1790 Apr 4, 1841 Mar 4, 1845
11 James K. Polk Nov 2, 1795 Mar 4, 1845 Mar 4, 1849
12 Zachary Taylor Nov 24, 1784 Mar 4, 1849 Jul 9, 1850
13 Millard Fillmore Jan 7, 1800 Jul 9, 1850 Mar 4, 1853
14 Franklin Pierce Nov 23, 1804 Mar 4, 1853 Mar 4, 1857
15 James Buchanan Apr 23, 1791 Mar 4, 1857 Mar 4, 1861
16 Abraham Lincoln Feb 12, 1809 Mar 4, 1861 Apr 15, 1865
17 Andrew Johnson Dec 29, 1808 Apr 15, 1865 Mar 4, 1869
18 Ulysses S. Grant Apr 27, 1822 Mar 4, 1869 Mar 4, 1877
19 Rutherford B. Hayes Oct 4, 1822 Mar 4, 1877 Mar 4, 1881
20 James A. Garfield Nov 19, 1831 Mar 4, 1881 Sep 19, 1881
21 Chester A. Arthur Oct 5, 1829 Sep 19, 1881 Mar 4, 1885
22 Grover Cleveland Mar 18, 1837 Mar 4, 1885 Mar 4, 1889
23 Benjamin Harrison Aug 20, 1833 Mar 4, 1889 Mar 4, 1893
24 Grover Cleveland Mar 18, 1837 Mar 4, 1893 Mar 4, 1897
25 William McKinley Jan 29, 1843 Mar 4, 1897 Sep 14, 1901
26 Theodore Roosevelt Oct 27, 1858 Sep 14, 1901 Mar 4, 1909
27 William H. Taft Sep 15, 1857 Mar 4, 1909 Mar 4, 1913
28 Woodrow Wilson Dec 28, 1856 Mar 4, 1913 Mar 4, 1921
29 Warren G. Harding Nov 2, 1865 Mar 4, 1921 Aug 2, 1923
30 Calvin Coolidge Jul 4, 1872 Aug 2, 1923 Mar 4, 1929
31 Herbert Hoover Aug 10, 1874 Mar 4, 1929 Mar 4, 1933
32 Franklin D. Roosevelt Jan 30, 1882 Mar 4, 1933 Apr 12, 1945
33 Harry S. Truman May 8, 1884 Apr 12, 1945 Jan 20, 1953
34 Dwight D. Eisenhower Oct 14, 1890 Jan 20, 1953 Jan 20, 1961
35 John F. Kennedy May 29, 1917 Jan 20, 1961 Nov 22, 1963
36 Lyndon B. Johnson Aug 27, 1908 Nov 22, 1963 Jan 20, 1969
37 Richard Nixon Jan 9, 1913 Jan 20, 1969 Aug 9, 1974
38 Gerald Ford Jul 14, 1913 Aug 9, 1974 Jan 20, 1977
39 Jimmy Carter Oct 1, 1924 Jan 20, 1977 Jan 20, 1981
40 Ronald Reagan Feb 6, 1911 Jan 20, 1981 Jan 20, 1989
41 George H. W. Bush Jun 12, 1924 Jan 20, 1989 Jan 20, 1993
42 Bill Clinton Aug 19, 1946 Jan 20, 1993 Jan 20, 2001
43 George W. Bush Jul 6, 1946 Jan 20, 2001 Jan 20, 2009
44 Barack Obama Aug 4, 1961 Jan 20, 2009 Jan 20, 2017
45 Donald Trump Jun 14, 1946 Jan 20, 2017 .
;
11 ods listing close;ods html5 file=stdout options(bitmap_mode='inline') device=png; ods graphics on / outputfmt=png;
NOTE: Writing HTML5 Body file: STDOUT
12
13 /* Program to accompany
14 Wicklin, R., "Visualize the ages of US presidents"
15 Published 14Nov2016 at The DO Loop blog
16 http://blogs.sas.com/content/iml/2016/11/14/viz-age-us-president.html
17
18 Data from
19 https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States_by_age
20 */
21 data Presidents;
22 input @1 N 2.
23 @4 President $23.
24 @28 BirthDate anydtdte12.
25 @44 InaugurationDate anydtdte12.
26 @60 PresidencyEndDate anydtdte12.
27 ;
28 /* use the YRDIF function to compute ages */
29 AgeAtInauguration = yrdif(BirthDate, InaugurationDate, 'ACT/ACT');
30 AgeAtEndDate = yrdif(BirthDate, PresidencyEndDate, 'ACT/ACT');
31 format BirthDate InaugurationDate PresidencyEndDate DATE10.;
32 label AgeAtInauguration="Age at First Inauguration"
33 AgeAtEndDate="Age at End of Term"
34 InaugurationDate="Inauguration Date";
35 /* get last names to use as labels */
36 LastName = scan(President, countw(President));
37 if AgeAtInauguration<=50 | AgeAtInauguration>=65 then
38 Label= LastName;
39 else Label=" ";
40 datalines;
NOTE: Invalid argument to function YRDIF(-4949,.,'ACT/ACT') at line 30 column 21.
RULE:----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
85 45 Donald Trump Jun 14, 1946 Jan 20, 2017 .
N=45 President=Donald Trump BirthDate=14JUN1946 InaugurationDate=20JAN2017 PresidencyEndDate=. AgeAtInauguration=70.602739726
AgeAtEndDate=. LastName=Trump Label=Trump _ERROR_=1 _N_=45
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 30:21
NOTE: The data set WORK.PRESIDENTS has 45 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
86 ;
87
88
89 ods html5 close;ods listing;
90
proc format lib=work;
value sign
'21Mar2000'd - '19Apr2000'd = 'Aries'
'20Apr2000'd - '20May2000'd = 'Taurus'
'21May2000'd - '20Jun2000'd = 'Gemini'
'21Jun2000'd - '22Jul2000'd = 'Cancer'
'23Jul2000'd - '22Aug2000'd = 'Leo'
'23Aug2000'd - '22Sep2000'd = 'Virgo'
'23Sep2000'd - '22Oct2000'd = 'Libra'
'23Oct2000'd - '21Nov2000'd = 'Scorpio'
'22Nov2000'd - '21Dec2000'd = 'Sagittarious'
/* split Capricorn to make two valid ranges */
/* that don't span the calendar boundary */
'22Dec2000'd - '31Dec2000'd = 'Capricorn'
'01Jan2000'd - '19Jan2000'd = 'Capricorn'
'20Jan2000'd - '18Feb2000'd = 'Aquarius'
'19Feb2000'd - '20Mar2000'd = 'Pisces'
other = 'Unknown';
run;
data signs;
/* So this column appears first */
retain President;
length sign 8;
format sign sign.;
set presidents (keep=President BirthDate InaugurationDate);
/* convert birthday to our normalized SIGN date */
sign = mdy(month(birthdate),day(birthdate),2000);
run;
92 ods listing close;ods html5 file=stdout options(bitmap_mode='inline') device=png; ods graphics on / outputfmt=png;
NOTE: Writing HTML5 Body file: STDOUT
93
94 proc format lib=work;
95
95 ! value sign
96 '21Mar2000'd - '19Apr2000'd = 'Aries'
97 '20Apr2000'd - '20May2000'd = 'Taurus'
98 '21May2000'd - '20Jun2000'd = 'Gemini'
99 '21Jun2000'd - '22Jul2000'd = 'Cancer'
100 '23Jul2000'd - '22Aug2000'd = 'Leo'
101 '23Aug2000'd - '22Sep2000'd = 'Virgo'
102 '23Sep2000'd - '22Oct2000'd = 'Libra'
103 '23Oct2000'd - '21Nov2000'd = 'Scorpio'
104 '22Nov2000'd - '21Dec2000'd = 'Sagittarious'
105 /* split Capricorn to make two valid ranges */
106 /* that don't span the calendar boundary */
107 '22Dec2000'd - '31Dec2000'd = 'Capricorn'
108 '01Jan2000'd - '19Jan2000'd = 'Capricorn'
109 '20Jan2000'd - '18Feb2000'd = 'Aquarius'
110 '19Feb2000'd - '20Mar2000'd = 'Pisces'
NOTE: Format SIGN has been output.
111 other = 'Unknown';
112 run;
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
113
114 data signs;
115 /* So this column appears first */
116 retain President;
117 length sign 8;
118 format sign sign.;
119 set presidents (keep=President BirthDate InaugurationDate);
120 /* convert birthday to our normalized SIGN date */
121 sign = mdy(month(birthdate),day(birthdate),2000);
122 run;
NOTE: There were 45 observations read from the data set WORK.PRESIDENTS.
NOTE: The data set WORK.SIGNS has 45 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
123
124 ods html5 close;ods listing;
125
ods html5 style=dove;
proc print data=signs;
var President sign;
run;
Obs | President | sign |
---|---|---|
1 | George Washington | Pisces |
2 | John Adams | Scorpio |
3 | Thomas Jefferson | Aries |
4 | James Madison | Pisces |
5 | James Monroe | Taurus |
6 | John Q. Adams | Cancer |
7 | Andrew Jackson | Pisces |
8 | Martin Van Buren | Sagittarious |
9 | William H. Harrison | Aquarius |
10 | John Tyler | Aries |
11 | James K. Polk | Scorpio |
12 | Zachary Taylor | Sagittarious |
13 | Millard Fillmore | Capricorn |
14 | Franklin Pierce | Sagittarious |
15 | James Buchanan | Taurus |
16 | Abraham Lincoln | Aquarius |
17 | Andrew Johnson | Capricorn |
18 | Ulysses S. Grant | Taurus |
19 | Rutherford B. Hayes | Libra |
20 | James A. Garfield | Scorpio |
21 | Chester A. Arthur | Libra |
22 | Grover Cleveland | Pisces |
23 | Benjamin Harrison | Leo |
24 | Grover Cleveland | Pisces |
25 | William McKinley | Aquarius |
26 | Theodore Roosevelt | Scorpio |
27 | William H. Taft | Virgo |
28 | Woodrow Wilson | Capricorn |
29 | Warren G. Harding | Scorpio |
30 | Calvin Coolidge | Cancer |
31 | Herbert Hoover | Leo |
32 | Franklin D. Roosevelt | Aquarius |
33 | Harry S. Truman | Taurus |
34 | Dwight D. Eisenhower | Libra |
35 | John F. Kennedy | Gemini |
36 | Lyndon B. Johnson | Virgo |
37 | Richard Nixon | Capricorn |
38 | Gerald Ford | Cancer |
39 | Jimmy Carter | Libra |
40 | Ronald Reagan | Aquarius |
41 | George H. W. Bush | Gemini |
42 | Bill Clinton | Leo |
43 | George W. Bush | Cancer |
44 | Barack Obama | Leo |
45 | Donald Trump | Gemini |
ods html5 style=dove;
ods graphics on;
proc freq data=signs order=freq;
tables sign / plots=freqplot;
run;
The FREQ Procedure
sign | Frequency | Percent | Cumulative Frequency |
Cumulative Percent |
---|---|---|---|---|
Aquarius | 5 | 11.11 | 5 | 11.11 |
Pisces | 5 | 11.11 | 10 | 22.22 |
Scorpio | 5 | 11.11 | 15 | 33.33 |
Cancer | 4 | 8.89 | 19 | 42.22 |
Capricorn | 4 | 8.89 | 23 | 51.11 |
Leo | 4 | 8.89 | 27 | 60.00 |
Libra | 4 | 8.89 | 31 | 68.89 |
Taurus | 4 | 8.89 | 35 | 77.78 |
Gemini | 3 | 6.67 | 38 | 84.44 |
Sagittarious | 3 | 6.67 | 41 | 91.11 |
Aries | 2 | 4.44 | 43 | 95.56 |
Virgo | 2 | 4.44 | 45 | 100.00 |