%let name=payphones; filename odsout '.'; /* https://metricmaps.files.wordpress.com/2016/02/payphone-hit.gif 2004, 2005, 2006 https://apps.fcc.gov/edocs_public/attachmatch/DOC-262086A1.pdf https://apps.fcc.gov/edocs_public/attachmatch/DOC-282813A1.pdf https://apps.fcc.gov/edocs_public/attachmatch/DOC-301505A1.pdf 2000 https://web.archive.org/web/20110531203821/http://transition.fcc.gov/Bureaus/Common_Carrier/Reports/FCC-State_Link/SOCC/00socc.pdf */ filename myfile 'payphones.txt'; data my_data (drop = whole_line date url i); retain url date year; infile myfile lrecl=200 pad; input whole_line $ 1-200; if index(whole_line,'http')^=0 then url=whole_line; else if index(whole_line,'31dec')^=0 then do; date=input(whole_line,date9.); year=.; year=year(date); end; else do; length statecode $2; statecode=scan(whole_line,-1,' '); payphones=.; if year<=2001 then payphones=input(scan(whole_line,-6,' '),comma20.0); else payphones=input(scan(whole_line,-5,' '),comma20.0); output; end; run; /* Merge in the year 2000 census population for each state */ proc sql noprint; create table my_data as select unique my_data.*, population_2000 as population from my_data left join sashelp.us_data on my_data.statecode=us_data.statecode; quit; run; /* Eliminate Hawaii, since they don't have data for all years */ data my_data; set my_data (where=(statecode^='HI')); payphones_per_1000=payphones/(population/1000); category=int(payphones_per_1000); if category>7 then category=7; run; proc sort data=my_data out=my_data; by year statecode; run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Payphones in the US") style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=4 htext=2.2; goptions ctext=gray33; proc sql noprint; create table plotdata as select unique year, sum(payphones) as payphones from my_data group by year; quit; run; data plotdata; set plotdata; length my_hytml $300; my_html= 'title='||quote( trim(left(put(payphones,comma12.0)))||' payphones'||'0d'x|| 'in '||trim(left(year)))|| ' href='||quote('#map'||trim(left(year))); run; axis1 label=none order=(0 to 2000000 by 250000) major=none minor=none style=0 offset=(0,0); axis2 label=none order=(1997 to 2007 by 1) major=none minor=none style=0 /*offset=(0,0)*/; symbol1 value=circle height=2.8 c=blue interpol=join ci=blue; title1 ls=1.5 "Number of Payphones in the Contiguous US, by year"; footnote link='https://www.fcc.gov/general/statistics-communications-common-carriers' c=gray ls=0.8 "Data source: fcc.gov (Statistics of Communications Common Carriers reports)"; goptions xpixels=800 ypixels=550; proc gplot data=plotdata; format payphones comma12.0; plot payphones*year / vaxis=axis1 haxis=axis2 noframe autovref cvref=graydd autohref chref=graydd html=my_html des='' name="&name"; run; %macro do_map(year); data tempdata; set my_data (where=(year=&year)); length my_html $300; my_html= 'title='||quote( trim(left(fipnamel(stfips(statecode))))||' (year '||trim(left(year))||')'||'0d'x|| trim(left(put(payphones_per_1000,comma8.1)))||' payphones per 1,000 state population'||'0d'x|| trim(left(put(payphones,comma12.0)))||' total payphones' ); run; legend1 position=(right middle) mode=share across=1 label=(position=top j=c 'Payphones' j=c 'Per 1,000' j=c 'State Population') order=descending shape=bar(.15in,.15in) offset=(3,-10); proc format; value pay_fmt 0='<1' 1='1-2' 2='2-3' 3='3-4' 4='4-5' 5='5-6' 6='6-7' 7='7+' ; run; pattern1 v=s c=cxfeffdb; pattern2 v=s c=cxdaf2b4; pattern3 v=s c=cxaaea8c; pattern4 v=s c=cx71dc6d; pattern5 v=s c=cx4dcd73; pattern6 v=s c=cx3abb86; pattern7 v=s c=cx22a499; pattern8 v=s c=cx0c5e8a; options nobyline; title1 ls=1.5 "Payphone prevalence, by state, in year &year"; title2 a=-90 h=7 ' '; ods html anchor="map&year"; goptions xpixels=850 ypixels=550; proc gmap data=tempdata map=maps.us uniform; format category pay_fmt.; id statecode; choro category / midpoints = 0 1 2 3 4 5 6 7 legend=legend1 html=my_html des='' name="&name._map_&year"; run; %mend; %do_map(1997); %do_map(1998); %do_map(1999); %do_map(2000); %do_map(2001); %do_map(2002); %do_map(2003); %do_map(2004); %do_map(2005); %do_map(2006); %do_map(2007); quit; ODS HTML CLOSE; ODS LISTING;