%let name=greenhouse_gas_us; filename odsout '.'; /* Imitation of graphs from: https://www3.epa.gov/climatechange/ghgemissions/inventoryexplorer/#allsectors/allgas/gas/all https://www3.epa.gov/climatechange/ghgemissions/inventoryexplorer/#allsectors/allgas/econsect/all Using data from: https://www3.epa.gov/climatechange/ghgemissions/data/1.csv https://www3.epa.gov/climatechange/ghgemissions/data/2.csv */ /* This file isn't in this web location any more, so I made a local copy. filename file1 url 'https://www3.epa.gov/climatechange/ghgemissions/data/1.csv'; */ filename file1 '1.csv'; proc import datafile=file1 out=data1 dbms=csv replace; getnames=yes; guessingrows=all; run; proc transpose data=data1 out=data1; by gas notsorted; run; data data1 (drop = _name_); set data1 (rename=(col1=mmt_co2_equiv)); year=.; year=substr(_name_,2,4); if gas='Carbon dioxide' then stack_order=4; if gas='Methane' then stack_order=3; if gas='Nitrous oxide' then stack_order=2; if gas='Fluorinated gases' then stack_order=1; if gas^='Total' then output; run; proc sql noprint; create table control as select unique stack_order as start, gas as label from data1; quit; run; data control; set control; fmtname='stk_fmt'; type='N'; run; proc format lib=work cntlin=control; run; /* filename file2 url 'https://www3.epa.gov/climatechange/ghgemissions/data/2.csv'; */ filename file2 '2.csv'; proc import datafile=file2 out=data2 dbms=csv replace; getnames=yes; guessingrows=all; run; proc transpose data=data2 out=data2; by Economic_Sector notsorted; run; data data2 (drop = _name_); set data2 (rename=(col1=mmt_co2_equiv)); year=.; year=substr(_name_,2,4); if economic_sector='Residential' then stack_order=1; if economic_sector='Commercial' then stack_order=2; if economic_sector='Agriculture' then stack_order=3; if economic_sector='Industry' then stack_order=4; if economic_sector='Transportation' then stack_order=5; if economic_sector='Electricity generation' then stack_order=6; if economic_sector^='Total' and economic_sector^='U.S. territories' then output; run; proc sql noprint; create table control as select unique stack_order as start, economic_sector as label from data2; quit; run; data control; set control; fmtname='stk_fmtb'; type='N'; run; proc format lib=work cntlin=control; run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Greenhouse Gase Emissions in US") style=htmlblue; goptions gunit=pct ftitle="albany amt" ftext="albany amt" htitle=4.25 htext=2.2; goptions ctext=gray33; legend1 label=none value=(j=l) position=(top center) order=descending colmajor offset=(5,0) shape=bar(.15in,.15in); axis1 label=(a=90 font='albany amt' height=2.5 j=c 'Emissions (million metric tons' j=c 'of carbon dioxide equivalents)') minor=none offset=(0,0) style=0; axis2 label=none value=(angle=90); pattern1 v=s c=cxeb5355; pattern2 v=s c=cx699eca; pattern3 v=s c=cxb27aba; pattern4 v=s c=cx79c377; title1 ls=1.5 "U.S. Greenhouse Gas Emissions, by Gas"; title2 a=-90 h=2 ' '; ods html anchor='gas'; proc gchart data=data1; format stack_order stk_fmt.; format mmt_co2_equiv comma8.0; vbar year / discrete type=sum sumvar=mmt_co2_equiv subgroup=stack_order legend=legend1 raxis=axis1 maxis=axis2 noframe autoref clipref cref=graydd space=0 coutline=gray55 des='' name="&name"; run; pattern1 v=s c=cxff9f40; pattern2 v=s c=cxe0e05b; pattern3 v=s c=cxeb5355; pattern4 v=s c=cxb27aba; pattern5 v=s c=cx699eca; pattern6 v=s c=cx79c377; title1 ls=1.5 "U.S. Greenhouse Gas Emissions, by Economic Sector"; title2 a=-90 h=2 ' '; ods html anchor='sector'; proc gchart data=data2; format stack_order stk_fmtb.; format mmt_co2_equiv comma8.0; vbar year / discrete type=sum sumvar=mmt_co2_equiv subgroup=stack_order legend=legend1 raxis=axis1 maxis=axis2 noframe autoref clipref cref=graydd space=0 coutline=gray55 des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;