%let name=anmpop; filename odsout '.'; /* This graph was originally written in v6 sas, and I'm using the option for v6 variable names, to keep the code working, in particular the variable names automatically created after I do the proc transpose */ options validvarname=v6 validvarname=upcase; /* Get the data you'll need to create the graphs, and summarize/transform it. (pop.sas7bdat and pop.sas7bndx) */ libname datalib '.' access=readonly ; proc sql; create table left as select year, sum( AGE0 , AGE1 , AGE2 , AGE3 , AGE4 ) as g18, sum( AGE5 , AGE6 , AGE7 , AGE8 , AGE9 ) as g17, sum( AGE10 , AGE11 , AGE12 , AGE13 , AGE14 ) as g16, sum( AGE15 , AGE16 , AGE17 , AGE18 , AGE19 ) as g15, sum( AGE20 , AGE21 , AGE22 , AGE23 , AGE24 ) as g14, sum( AGE25 , AGE26 , AGE27 , AGE28 , AGE29 ) as g13, sum( AGE30 , AGE31 , AGE32 , AGE33 , AGE34 ) as g12, sum( AGE35 , AGE36 , AGE37 , AGE38 , AGE39 ) as g11, sum( AGE40 , AGE41 , AGE42 , AGE43 , AGE44 ) as g10, sum( AGE45 , AGE46 , AGE47 , AGE48 , AGE49 ) as g09, sum( AGE50 , AGE51 , AGE52 , AGE53 , AGE54 ) as g08, sum( AGE55 , AGE56 , AGE57 , AGE58 , AGE59 ) as g07, sum( AGE60 , AGE61 , AGE62 , AGE63 , AGE64 ) as g06, sum( AGE65 , AGE66 , AGE67 , AGE68 , AGE69 ) as g05, sum( AGE70 , AGE71 , AGE72 , AGE73 , AGE74 ) as g04, sum( AGE75 , AGE76 , AGE77 , AGE78 , AGE79 ) as g03, sum( AGE80 , AGE81 , AGE82 , AGE83 , AGE84 ) as g02, AGE85 as g01, 0 as g00 from datalib.pop where (state=upcase('NC')) and (race=0) and (sex=1) and year between 1993 and 2020 order by year; quit; run; proc transpose data=left out=left; by year; run; data left; set left; pop=-1*col1; group='left '; run; proc sql; create table right as select year, sum( AGE0 , AGE1 , AGE2 , AGE3 , AGE4 ) as g18, sum( AGE5 , AGE6 , AGE7 , AGE8 , AGE9 ) as g17, sum( AGE10 , AGE11 , AGE12 , AGE13 , AGE14 ) as g16, sum( AGE15 , AGE16 , AGE17 , AGE18 , AGE19 ) as g15, sum( AGE20 , AGE21 , AGE22 , AGE23 , AGE24 ) as g14, sum( AGE25 , AGE26 , AGE27 , AGE28 , AGE29 ) as g13, sum( AGE30 , AGE31 , AGE32 , AGE33 , AGE34 ) as g12, sum( AGE35 , AGE36 , AGE37 , AGE38 , AGE39 ) as g11, sum( AGE40 , AGE41 , AGE42 , AGE43 , AGE44 ) as g10, sum( AGE45 , AGE46 , AGE47 , AGE48 , AGE49 ) as g09, sum( AGE50 , AGE51 , AGE52 , AGE53 , AGE54 ) as g08, sum( AGE55 , AGE56 , AGE57 , AGE58 , AGE59 ) as g07, sum( AGE60 , AGE61 , AGE62 , AGE63 , AGE64 ) as g06, sum( AGE65 , AGE66 , AGE67 , AGE68 , AGE69 ) as g05, sum( AGE70 , AGE71 , AGE72 , AGE73 , AGE74 ) as g04, sum( AGE75 , AGE76 , AGE77 , AGE78 , AGE79 ) as g03, sum( AGE80 , AGE81 , AGE82 , AGE83 , AGE84 ) as g02, AGE85 as g01, 0 as g00 from datalib.pop where (state=upcase('NC')) and (race=0) and (sex=2) and year between 1993 and 2020 order by year; quit; run; proc transpose data= right out= right; by year; run; data right; set right; pop=col1; group='right'; run; proc format; picture posval low-high='000,009'; run; data both; set left right; label age_grp='00'x; label year='00'x; format pop posval.; age_grp=_name_; run; proc sort data=both out=both; by year; run; data label1; xsys='2'; ysys='2'; hsys='3'; when='a'; function='label'; position='5'; size=3; age_grp='G02'; x=250000; yc=age_grp; text = 'Female'; color = 'pink'; output; x=-250000; yc=age_grp; text = 'Male'; color = 'cyan'; output; run; goptions xpixels=800 ypixels=600 hsize= vsize=; goptions noborder; options dev=sasprtc printerpath=gif animduration=.4 animloop=0 animoverlay=no animate=start center; ods listing close; ods html path=odsout body="&name..htm" (title="North Carolina Population Distribution (SAS/Graph gif animation)") style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=5 htext=2.4; goptions ctext=gray33; footnote1 j=l ' Data Source: Census Population Projections' j=r 'NCSU Textile/Apparel Business Information System (TABIS) '; axis1 label=none value=( ' Age ' '85+ ' '80-84' '75-79' '70-74' '65-69' '60-64' '55-59' '50-54' '45-49' '40-44' '35-39' '30-34' '25-29' '20-24' '15-19' '10-14' ' 5-9 ' ' 0-4 ') ; axis2 label=none major=(number=9) order=(-400000 to 400000 by 100000) minor=(color=gray99) offset=(0,0); pattern1 v=s c=cyan; pattern2 v=s c=pink; title1 ls=1.5 'North Carolina Population Distribution '; options nobyline; title2 h=4 font="albany amt/bold" "#byval(year)"; proc gchart data=both annotate=label1; by year; hbar age_grp / discrete type=sum sumvar=pop space=0 subgroup=group maxis=axis1 raxis=axis2 nostats nolegend frame autoref cref=white cframe=gray coutline=gray caxis=black des='' name="&name"; run; quit; ods html close; ods listing;