/* SAS Code to create Population Pyramids written by Larry Hoyle and Xan Stevens The University of Kansas Policy Research Institute 1541 Lilac Lane, Suite 607 Lawrence, Kansas 66044-3177 (785) 864-3701 http://www.ku.edu/pri/ */ /* This code uses the SAS data set extracted from 2000 Census SF1 PCT tables for a SINGLE STATE. This data set was created using the SAS code developed by the SDC network (full credits at http://www.ku.edu/pri/ksdata/census/2000/index.shtml#sf1credits).*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* SEARCH for 'ENTER' to find all areas where information must be added.*/ /* Code will produce THREE items for each county/state. TWO are .gifs, */ /* one small and one larger; and ONE .htm file containing a table of the*/ /* data and the small .gif. When the user clicks on the small .gif the */ /* larger .gif will appear. */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*ENTER location of SF1 PCT SAS data set HERE */ libname sf1 'd:/data/census/2000/sf1/'; %let winsiz=1000; /*window size*/ %let ttlx=500; %let ttly=930; %let ttlht=25; /*height of title*/ %let mfht=20; %let xaxtxht=20; %let yaxtxht=20; %let barwdth=8; %let linspc=0; %let leftmrg=50; /*LEFT margin*/ %let botmrg=50; /*BOTTOM margin */ %let xaxisy=45; %let cntrmrg=100; %let grwdth=400; %let font=swissb; /*ENTER the destination directory for output files */ %let outdir=d:\data\poppyramids\temp; data ages; /*ENTER file name of SAS data set that contains PCT tables from 2000 SF1 (two letter state abbreviation followed by 'pct') */ set sf1.kspct; where sumlev='050' or (sumlev='040' and GeoComp='00'); /*select state and county level data*/ keep geocode areaname pct12i1-pct12i209; run; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* | The IMGSIZE macro lets you modify the size of the image area | in pixel units. | | Notes: | 1. The dots per inch value (dpi) should be the same as | that used by the driver (dpi=xpixels/xmax). | | 2. The maximum width and height values specified as | parameters should not exceed the xmax and ymax values | of the device used. The default values used below | are arbitrary. */ %macro IMGSIZE(w=1280, h=1024, dpi=95, rows=43, cols=83); %if &dpi<=0 %then %put DPI must be greater than zero.; %else %do; goptions hsize=%sysevalf(&w/&dpi)in vsize=%sysevalf(&h/&dpi)in hpos=&cols vpos=&rows; %end; %mend IMGSIZE; %IMGSIZE(w=799, h=599, dpi=95, rows=43, cols=83); goptions device=gif gsfmode=replace gsfname=pyrout ; data _null_; set ages end=last; length hrefg $ 100 hrefh $ 100 frefh $ 200; length hrefn $ 100 ; hrefg='ppbig'||trim(geocode)||'.gif'; hrefh='pptab'||trim(geocode)||'.htm'; frefh=trim("&outdir\"||left(hrefh)); hrefn='ppsmall'||trim(geocode)||'.gif'; put hrefg=; put hrefh=; put frefh=; /* assign fileref for this county */ rc=filename('PYROUT',trim("&outdir\"||left(hrefg))); sysmess=sysmsg(); if rc then put 'error assigning pyrout' rc= / sysmess; /* write index html file */ file htmlindx; /* header */ if _n_=1 then do; put ''; put '
'; put '| ' areaname ; put ' | pyramid' ', '; put ' | table' ''; /* trailer */ if last then do; put ' |
| ' areaname ' 2000 Population by Age by Gender'; put ''; put ' | ||||||||||||
| AGE' ' | Male' ' | Female | '; put '||||||||||
| ' ' | Number' ' | Percent' ' | Number' ' | Percent'; /* plot a pair of bars for each age */ /* and write out rows of an html table */ do ia=1 to 103; ia0=ia-1; barybot=&botmrg+(ia0*(&barwdth+&linspc)); barytop=&botmrg+(ia0*(&barwdth+&linspc))+&barwdth; if mod(ia,5) = 1 then do; rc=gset('filcolor',1); rc=gset('lincolor',1); rc=gset('filtype','SOLID'); /* y axis label */ rc=gset('texcolor',3); rc=gset('texfont',"&font"); rc=gset('texheight',&yaxtxht); rc=gset('texalign','CENTER','BASE'); ylbl=left(put(ia0,3.)); rc=gdraw('text',&ttlx,barybot,ylbl); end; else do; rc=gset('filcolor',1); rc=gset('lincolor',1); rc=gset('filtype','HOLLOW'); end; put ' | ||||||||
| under 1 year"; end; when (ia0>0 and ia0<10) do; put ' | 'ia0; end; when (ia0>=10 and ia0<100) do; put " | "ia0; end; when (ia0=100) do; put " | 100 to 104"; end; when (ia0=101) do; put " | 105 to 109"; end; when (ia0=102) do; put " | 110 and over"; end; otherwise put ' | unknown'; end; /* table */ put ' | ' males{ia+1} ' | ' '' pctmale{ia+1} percent7.1 ' | ' '' females{ia+1} ' | ' '' pctfemale{ia+1} percent7.1 ' | ' ; /* graph */ pctmaxM=pctmale{ia+1}/axishi; pctmaxF=pctfemale{ia+1}/axishi; barlenM=&grwdth*pctmaxM; barlenF=&grwdth*pctmaxF; /* MALES */ barxleft=floor(&grwdth+&leftmrg-barlenM); barxright=floor(&grwdth+&leftmrg); rc=gdraw('bar',barxleft,barybot,barxright,barytop); /* FEMALES */ barxleft=&grwdth+&leftmrg+&cntrmrg; barxright=floor(&grwdth+&leftmrg+&cntrmrg+barlenF); rc=gdraw('bar',barxleft,barybot,barxright,barytop); if ia0=30 then put ''; if ia0=82 then put ' | ';
if ia0=30 or ia0 = 82 then do;
put '';
/*ENTER specific contact info from here ...*/
put '';
put 'Policy Research Institute,';
put ' '; put ''; put 'The University of Kansas'; /* .... TO HERE */ put ' '; put ' Source:'
' '; put 'Please email comments to:' ; /*ENTER specific contact info HERE ...*/ put " " @; put 'pri@ku.edu' @; put ' '; put ' | ';
end; /* if ia0=30 */
if ia0=51 then do;
put '
(' areaname ' continued)
'; put '| AGE' ' | Male' ' | Female | '; put '|||
| ' ' | Number' ' | Percent' ' | Number' ' | Percent'; end; /* if ia0=51 */ end; /* do ia=1 to 103 */ /* end of this table */ put ' | |