x cd /pub/data/popests; %let pgm=nchsbri_super_summary; filename pgm "&pgm..sas"; *---Create a "super summary" dataset from the latest (thru 2009 vintage) nchsbri pop estimats time series datasets. We create the single dataset nchsbri.super_summary with one obs per state|county / year, with year taking on only values 1990, 2000 and 2009. Variables are basic demographics based on age, race, hispanic and sex. The only crossing of any of these will be for white/non-hispanic. John Blodgett, OSEDA, September, 2010. Intended for use in generating reports via rankster in the webrepts/rankster collection. ---*; libname nchsbri '/pub/data/popests/nchsbri'; %let state=10; %let stab=de; %macro doit(state,stab); data aggin&stab; length fipco $5; set nchsbri.&stab.nchsbridged19xx_sumry (where=(year='1990')) nchsbri.&stab.nchsbridged20xx_sumry (where=(year in ('2000','2009'))); by state county year; array vars(*) Total Male Female White WhiteNH Black AsianPI AmInd Hispanic ; array pctvars(*) PctTotal PctMale PctFemale PctWhite PctWhiteNH PctBlack PctAsianPI PctAmInd PctHispanic ; array savevars(9) _temporary_; array agevars(14 ) age0_4 age5_17 age18_24 age25_34 age35_44 age45_54 age55_64 age65_74 age75_84 age85up age0_17 age20up age62up age65up; array pctavars(14 ) PctAge0_4 PctAge5_17 PctAge18_24 PctAge25_34 PctAge35_44 PctAge45_54 PctAge55_64 PctAge65_74 PctAge75_84 PctAge85up PctAge0_17 PctAge20up PctAge62up PctAge65up; if first.year then do; do _i=1 to 9; savevars(_i)=vars(_i); Pctvars(_i)=.; end; do _i=1 to dim(agevars); agevars(_i)=0; pctavars(_i)=.; end; delete; *--the first obs for a year group contains the totals across all ages---; end; length nage 8; nage=age; *--if we get here then we have a value for age which we use to accumulate the age-based variables--; if nage <= 4 then age0_4 + Total; else if nage <=17 then age5_17+Total; else if nage <=24 then age18_24 + Total; else if nage <=34 then age25_34 + Total; else if nage <=44 then age35_44 + Total; else if nage <=54 then age45_54 + Total; else if nage <=64 then age55_64 + Total; else if nage <=74 then age65_74 + Total; else if nage <=84 then age75_84 + Total; else age85up + Total; if nage >=20 then age20up + Total; if nage >=62 then age62up + Total; if last.year then do; do _i=1 to 9; vars(_i)=savevars(_i); pctvars(_i)=100*vars(_i)/Total; end; age0_17=age0_4 + age5_17; age65up=sum(of age65_74--age85up); do _i=1 to 14; pctavars(_i)=100*agevars(_i)/Total; end; fipco=county; format county $county.; output; end; keep sumlev state county fipco year Total--amind AsianPI Hispanic age0_4 -- age62up; length Pct: 4; format Pct: 5.1 Total--amind AsianPI Hispanic comma9.; keep Pct: ; drop PctTotal BlackNH; run; %if %superq(stab)=de %then %do; proc print data= aggin&stab; by state; id sumlev county; run; %end; %mend doit; %dostates(n=51,names=1,msgs=1) %macro dset(state,stab); aggin&stab %mend doit; data nchsbri.ussuper_summary(label='Selected Summaries for US States and Counties Years 1990, 2000, 2009' index=(state)); set %dostates(n=51,mac=dset) open=defer; run; proc freq data=nchsbri.super_summary; table state*sumlev; run;