%let name=technology_adoption_us; /* Set your current-working-directory (to read/write files), if you need to ... %let rc=%sysfunc(dlgcdir('c:\someplace\public_html')); */ filename odsout '.'; /* Trying to improve this graph: https://www.reddit.com/r/dataisbeautiful/comments/dawtfr/technology_adoption_in_us_households_oc/ Using data from: https://ourworldindata.org/grapher/technology-adoption-by-households-in-the-united-states */ proc import datafile="technology-adoption-by-households-in-the-united-states.csv" dbms=csv replace out=my_data (rename=(Technology_Diffusion__Comin_and=Technology_Diffusion)); getnames=yes; datarow=2; run; data my_data; set my_data (drop=code); format Technology_Diffusion percent7.0; Technology_Diffusion=(Technology_Diffusion/100); if entity='Colour TV' then entity='Color TV'; run; proc sql noprint; create table entities as select unique entity from my_data; quit; run; data my_data; set my_data; if entity in ( 'Washing machine' 'Landline' 'Flush toilet' 'Automobile' 'Household refrigerator' 'Home air conditioning' ) then id='plot1'; if entity in ( 'Cellular phone' 'Cable TV' 'Microwave' 'Color TV' 'Computer' 'Internet' 'Social media usage' ) then id='plot2'; run; %let color1=cxa6761d; %let color2=cx66a61e; %let color3=cxe7298a; %let color4=cx7570b3; %let color5=cxd95f02; %let color6=cx1b9e77; %let color7=cxf781bf; %let color8=cxa65628; %let color9=cxff7f00; %let color10=cx984ea3; %let color11=cx4daf4a; %let color12=cx377eb8; %let color13=cxe41a1c; /* Keep the colors consistent, if data or data order changes */ data myattrs; length value linecolor markercolor $100; id="attr1"; linecolor="&color1"; markercolor="&color1"; value='Washing machine'; output; linecolor="&color2"; markercolor="&color2"; value='Landline'; output; linecolor="&color3"; markercolor="&color3"; value='Flush toilet'; output; linecolor="&color4"; markercolor="&color4"; value='Automobile'; output; linecolor="&color5"; markercolor="&color5"; value='Household refrigerator'; output; linecolor="&color6"; markercolor="&color6"; value='Home air conditioning'; output; id="attr2"; linecolor="&color7"; markercolor="&color7"; value='Cellular phone'; output; linecolor="&color8"; markercolor="&color8"; value='Cable TV'; output; linecolor="&color9"; markercolor="&color9"; value='Microwave'; output; linecolor="&color10"; markercolor="&color10"; value='Color TV'; output; linecolor="&color11"; markercolor="&color11"; value='Computer'; output; linecolor="&color12"; markercolor="&color12"; value='Internet'; output; linecolor="&color13"; markercolor="&color13"; value='Social media usage'; output; run; data my_anno; set my_data; if year=2016 and Entity='Landline' then output; if year=1940 and Entity='Flush toilet' then output; if year=1925 and Entity='Automobile' then output; if year=1951 and Entity='Household refrigerator' then output; if year=1954 and Entity='Washing machine' then output; if year=1970 and Entity='Home air conditioning' then output; if year=1970 and Entity='Color TV' then output; if year=1980 and Entity='Cable TV' then output; if year=1986 and Entity='Microwave' then output; if year=1998 and Entity='Computer' then output; if year=2009 and Entity='Cellular phone' then output; if year=2004 and Entity='Internet' then output; if year=2009 and Entity='Social media usage' then output; run; data my_anno; set my_anno; length label $300 anchor x1space y1space function $50 textcolor textweight $12; layer='front'; function='text'; x1=year; y1=Technology_Diffusion; x1space='datavalue'; y1space='datavalue'; label=trim(left(entity)); textcolor="gray99"; if entity='Washing machine' then textcolor="&color1"; if entity='Landline' then textcolor="&color2"; if entity='Flush toilet' then textcolor="&color3"; if entity='Automobile' then textcolor="&color4"; if entity='Household refrigerator' then textcolor="&color5"; if entity='Home air conditioning' then textcolor="&color6"; if entity='Cellular phone' then textcolor="&color7"; if entity='Cable TV' then textcolor="&color8"; if entity='Microwave' then textcolor="&color9"; if entity='Color TV' then textcolor="&color10"; if entity='Computer' then textcolor="&color11"; if entity='Internet' then textcolor="&color12"; if entity='Social media usage' then textcolor="&color13"; anchor="center"; if entity in ('Flush toilet' 'Automobile' 'Household refrigerator' 'Washing machine' 'Color TV' 'Cable TV' 'Microwave' 'Computer' 'Cellular phone') then anchor="bottomright"; if entity in ('Landline') then anchor="topright"; if entity in ('Home air conditioning' 'Internet' 'Social media usage') then anchor="topleft"; textsize=10; textweight='bold'; width=11; widthunit='percent'; run; /* Since ods graphics footnote does not support url links yet, annotate the footnote (annotated text supports url links). */ data anno_footnote; length label $100 anchor x1space y1space function $50 textcolor $12; layer='front'; function='text'; x1=50; y1=3; x1space='wallpercent'; y1space='graphpercent'; anchor='center'; textcolor="gray99"; textsize=10; textweight='normal'; width=100; widthunit='percent'; url="https://ourworldindata.org/grapher/technology-adoption-by-households-in-the-united-states"; label="Data source: Comin and Hobijn (2004) and others, ourworldindata.org"; id='plot1'; output; id='plot2'; output; run; data anno_all; set my_anno anno_footnote; run; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Technology Adoption in US Households") style=htmlblue; ods graphics / noscale /* if you don't use this option, the text will be resized */ imagemap tipmax=2500 imagefmt=png imagename="&name" width=1000px height=500px noborder; title1 color=gray33 h=18pt "Technology Adoption in US Households (Historical)"; proc sgplot data=my_data (where=(id='plot1')) sganno=anno_all (where=(id='plot1')) pad=(bottom=6pct) noborder noautolegend dattrmap=myattrs; series x=year y=Technology_Diffusion / group=Entity attrid=attr1 lineattrs=(thickness=2px) markers markerattrs=(size=6px symbol=circlefilled); yaxis display=(nolabel noticks noline) valueattrs=(color=gray33 size=10pt) offsetmin=0 offsetmax=0 grid gridattrs=(color=graydd); xaxis display=(nolabel noticks noline) values=(1900 to 2020 by 10) valueattrs=(color=gray33 size=10pt) offsetmin=0 offsetmax=0 grid gridattrs=(color=graydd); run; title1 color=gray33 h=18pt "Technology Adoption in US Households (Recent)"; proc sgplot data=my_data (where=(id='plot2')) sganno=anno_all (where=(id='plot2')) pad=(bottom=6pct) noborder noautolegend dattrmap=myattrs; series x=year y=Technology_Diffusion / group=Entity attrid=attr2 lineattrs=(thickness=2px) markers markerattrs=(size=6px symbol=circlefilled); yaxis display=(nolabel noticks noline) valueattrs=(color=gray33 size=10pt) offsetmin=0 offsetmax=0 grid gridattrs=(color=graydd); xaxis display=(nolabel noticks noline) values=(1965 to 2020 by 5) valueattrs=(color=gray33 size=10pt) offsetmin=0 offsetmax=0 grid gridattrs=(color=graydd); run; quit; ODS HTML CLOSE; ODS LISTING;