x cd /pub/data/popests/Tools; %let pgm=poptrends; filename pgm "&pgm..sas"; /*--Create the state and nation-level poptrends datasets that will be used to create the corresponding poptrends web reports. These datasets/report are based on the raw data taken from the nchsi bridged race summary datasts for the 1990s and 2000s. jgb, 4-15-08 (begin work). 10-08: Update with latest (2007) data. All we did was change the parm value of latestyr to 07 and more entries to $yearix. --; After running, you should update the entry in the datasets dataset for the ustrends data set to reflect new years value. 9-09 : Update with the 2008 data. 9-10 : Update with the 2009 data. 9-7-10: rerunning the conversion to foix problem with US trends dataset where the single-year periods were bad. --*/; /* filename mprint 'poptrends.mprint.sas'; options mfile; */ title "&pgm.: Pop Trends Based on the nchsbri estimates for the decades of the 90s and the 00s"; *filename deftpl '/pub/data/system/tableeditor/tableeditor.tpl'; libname nchsbri '/pub/data/popests/nchsbri' ; libname user '/SAS_temp/userb'; libname popests '/pub/data/popests' access=readonly; %let latestyr=09; %let latestyear=20&latestyr; %let nyears=9; *<---check each year!!--; *--the years are 1990, 1995, 2000, 2003, 2005, 2006, 2007, 2008, 2009 --; %let debug=0; *---optional generation of debugging info---; proc format; *---this format takes the year and returns the index in our table where we store the data for that year--; Value $yearix '1990'=1 '1995'=2 '2000'='3' '2003'=4 '2005'=5 '2006'=6 '2007'=7 '2008'=8 '2009'=9 '2010'=10 other=0; *<==================Add another entry in 2012 !!!!=; Value $demog 01='Total Population' 02='White' 03='White non-hispanic' 04='Black' 05='American Indian, Etc' 06='Asian or Pac Islndr' 07='Hispanic' 08='Non-hispanic' 09='Pop Aged 0 to 17' 10='Pop Aged 18 to 24' 11='Pop Aged 25 to 44' 12='Pop Aged 45 to 64' 13='Pop Aged 65+'; run; %*let state=29; %*let stab=mo; %macro doit(state,stab); data aggin/view=aggin; set nchsbri.&stab.nchsbridged19xx_sumry (where=(year in ('1990','1995'))) nchsbri.&stab.nchsbridged20xx_sumry (where=(year='2000' or year='2003' or year ge '2005')); run; proc means data=aggin missing noprint nway; class county year age_cohort1; var total white whitenh black amind asianpi hispanic nonhispanic; output out=aggout&stab(drop=_type_ _freq_) sum=; run; data &stab.trends(label="Trends in pop ests based on nchsbri data 1990 to &latestyear"); length SumLev $3 State $2; length County $5 PerNo 3 Period $12 Demographic $2 StartPop PctStart EndPop PctEnd Change PctChange AnnualizedChange AnnualizedPctChange 5; keep sumlev state county -- AnnualizedPctChange; format StartPop EndPop comma11. Change AnnualizedChange comma10. PctStart PctEnd 5.1 PctChange AnnualizedPctChange 6.1; array est(&nyears,13) _temporary_; set aggout&stab; by county year; *---We save these 13 demographic categories including all 4 race groups and the 5 broad age groups. Nothing is crossed.-; _iyr=0; *--makes it numeric-; _iyr=put(year,$yearix.); IF _iyr=0 or ( _iyr > &nyears) THEN Do; put / '***Logic Problem assigning _iyr: ' _all_; abort abend; end; if age_cohort1=' ' then do; est{_iyr,1}=Total; est{_iyr,2}=white; est{_iyr,3}=whitenh; est{_iyr,4}=Black; est{_iyr,5}=AmInd; est{_iyr,6}=AsianPI; est{_iyr,7}=Hispanic; est{_iyr,8}=NonHispanic; end; else select(age_cohort1); when('00') est{_iyr,9}=total; when('18') est{_iyr,10}=total; when('25') est{_iyr,11}=total; when('45') est{_iyr,12}=total; when('65') est{_iyr,13}=total; otherwise do; put / '****Logic problem: unrecognized age_cohort1 value: ' age_cohort1= / _all_; abort abend; end; end; *---Select--; if last.county then do; *---here is where we build and write the output, a series of time-period trend summaries for the current geographic area. (County includes state here)---; if length(county)=2 then SumLev='040'; else SumLev='050'; State=substr(county,1,2); do _idemog=1 to 13; Demographic=put(_idemog,z2.); *<---demographic category code. 2-char with leading 0. See format code, above.--; PerNo=1; Period="1990 to &latestyear"; _periodLen=&latestyear - 1990; StartPop=est{1,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{1,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=2; Period="1990 to 2000"; _periodLen=10; StartPop=est{1,_idemog}; EndPop=est{3,_idemog}; _starttot=est{1,1}; _endtot=est{3,1};link trendcode; PerNo=3; Period="1990 to 1995"; _periodlen=5; StartPop=est{1,_idemog}; EndPop=est{2,_idemog}; _starttot=est{1,1}; _endtot=est{2,1}; link trendcode; PerNo=4; Period="1995 to 2000"; _periodlen=5; StartPop=est{2,_idemog}; EndPop=est{3,_idemog}; _starttot=est{2,1}; _endtot=est{3,1}; link trendcode; PerNo=5; Period="2000 to &latestyear"; _periodlen=&latestyr; StartPop=est{3,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{3,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=6; Period="2000 to 2005"; _periodlen=5; StartPop=est{3,_idemog}; EndPop=est{5,_idemog}; _starttot=est{3,1}; _endtot=est{5,1}; link trendcode; PerNo=7; Period="2000 to 2003"; _periodlen=3; StartPop=est{3,_idemog}; EndPop=est{4,_idemog}; _starttot=est{3,1}; _endtot=est{4,1}; link trendcode; PerNo=8; Period="2003 to 2006"; _periodlen=3; StartPop=est{4,_idemog}; EndPop=est{6,_idemog}; _starttot=est{4,1}; _endtot=est{6,1}; link trendcode; PerNo=9; Period="2006 to 2009"; _periodlen=3; StartPop=est{6,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{6,1}; _endtot=est{&nyears,1}; link trendcode; _periodlen=1; do _ix=6 to (&nyears -1); *<--check low limit each year---; length _yearlow _yearhi $4; length _yearlow _yearhi $4; _yearlow=2000+_ix; _ixp1=_ix+1; _yearhi=2000+_ixp1; PerNo=PerNo+1; Period=_yearlow||' to '||_yearhi; StartPop=est(_ix,_idemog); EndPop=est{_ixp1,_idemog}; _starttot=est{_ix,1}; _endtot=est{_ixp1,1}; link trendcode; end; end; *---the _idemog loop in which we ouput a set of trends for for each of the specified demographic categories-; *----We could "blank out" the est array here but it should not be necessary-------------------------; end; *---last.county processing---; return; trendcode: Change=EndPop - StartPop; if StartPop then PctChange=100*Change/StartPop; else PctChange=.; PctStart=StartPop*100/_starttot; PctEnd=EndPop*100/_endtot; if _periodlen ne . and StartPop then do; AnnualizedChange=Change/_periodLen; AnnualizedPctChange= 100*((Endpop/StartPop)**(1/_periodLen)-1); end; else do; AnnualizedChange=.; AnnualizedPctChange=.; *---why repeat what is already shown as the value for the 1-year interval?-; end; output; if &debug then if length(county)=2 then put / _all_; return; run; %if %superq(stab)=mo %then %do; proc freq data=&stab.trends; tables state sumlev county demographic ; tables PerNo*period/list; format county $county. demographic $demog.; title2 "Freq Reports on nchsbri.&stab.trends"; run ; %end; %mend doit; *<===================comment out these steps. Nothing changed and the userb directory appears to be intact=====; %*****dostates(names=1,msgs=1) ; *<====generate the 51 &stab.trends datasets on user lib ---; *-----This code being added 5/09 to create US totals summaries---------------------------*; %let debug=1; %macro aggout_(state,stab); aggout&stab %mend aggout_; *<---Used to reference all the 51 state aggout sets----; data agginustots; set %dostates(n=51,mac=aggout_) open=defer; where length(county)=2; state='00'; county=state; run; proc means data=agginustots missing noprint nway; class state county year age_cohort1; var total white whitenh black amind asianpi hispanic nonhispanic; output out=aggoutustots(drop=_type_ _freq_) sum=; run; proc sort data=aggoutustots; by year age_cohort1; run; *---this step pretty much duplicates the one from above but with different first and last processing-; data ustottrends(label="Trends in pop ests based on nchsbri data 1990 to &latestyear"); length SumLev $3 State $2; length County $5 PerNo 3 Period $12 Demographic $2 StartPop PctStart EndPop PctEnd Change PctChange AnnualizedChange AnnualizedPctChange 5; keep sumlev state county -- AnnualizedPctChange; format StartPop EndPop comma11. Change AnnualizedChange comma10. PctStart PctEnd 5.1 PctChange AnnualizedPctChange 6.1; array est(&nyears,13) _temporary_; set aggoutustots; by state; *---We save these 13 demographic categories including all 4 race groups and the 5 broad age groups. Nothing is crossed.-; _iyr=0; *--makes it numeric-; _iyr=put(year,$yearix.); IF _iyr=0 or ( _iyr > &nyears) THEN Do; put / '***Logic Problem assigning _iyr: ' _all_; abort abend; end; if age_cohort1=' ' then do; est{_iyr,1}=Total; est{_iyr,2}=white; est{_iyr,3}=whitenh; est{_iyr,4}=Black; est{_iyr,5}=AmInd; est{_iyr,6}=AsianPI; est{_iyr,7}=Hispanic; est{_iyr,8}=NonHispanic; end; else select(age_cohort1); when('00') est{_iyr,9}=total; when('18') est{_iyr,10}=total; when('25') est{_iyr,11}=total; when('45') est{_iyr,12}=total; when('65') est{_iyr,13}=total; otherwise do; put / '****Logic problem: unrecognized age_cohort1 value: ' age_cohort1= / _all_; abort abend; end; end; *---Select--; if last.state then do; *---here is where we build and write the output, a series of time-period trend summaries for the current geographic area. (County includes state here)---; SumLev='010'; do _idemog=1 to 13; Demographic=put(_idemog,z2.); *<---demographic category code. 2-char with leading 0. See format code, above.--; PerNo=1; Period="1990 to &latestyear"; _periodLen=&latestyear - 1990; StartPop=est{1,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{1,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=2; Period="1990 to 2000"; _periodLen=10; StartPop=est{1,_idemog}; EndPop=est{3,_idemog}; _starttot=est{1,1}; _endtot=est{3,1};link trendcode; PerNo=3; Period="1990 to 1995"; _periodlen=5; StartPop=est{1,_idemog}; EndPop=est{2,_idemog}; _starttot=est{1,1}; _endtot=est{2,1}; link trendcode; PerNo=4; Period="1995 to 2000"; _periodlen=5; StartPop=est{2,_idemog}; EndPop=est{3,_idemog}; _starttot=est{2,1}; _endtot=est{3,1}; link trendcode; PerNo=5; Period="2000 to &latestyear"; _periodlen=&latestyr; StartPop=est{3,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{3,1}; _endtot=est{&nyears,1}; link trendcode; PerNo=6; Period="2000 to 2005"; _periodlen=5; StartPop=est{3,_idemog}; EndPop=est{4,_idemog}; _starttot=est{3,1}; _endtot=est{4,1}; link trendcode; PerNo=7; Period="2000 to 2003"; _periodlen=3; StartPop=est{3,_idemog}; EndPop=est{4,_idemog}; _starttot=est{3,1}; _endtot=est{4,1}; link trendcode; PerNo=8; Period="2003 to 2006"; _periodlen=3; StartPop=est{4,_idemog}; EndPop=est{6,_idemog}; _starttot=est{4,1}; _endtot=est{6,1}; link trendcode; PerNo=9; Period="2006 to 2009"; _periodlen=3; StartPop=est{6,_idemog}; EndPop=est{&nyears,_idemog}; _starttot=est{6,1}; _endtot=est{&nyears,1}; link trendcode; _periodlen=1; do _ix=6 to (&nyears -1); length _yearlow _yearhi $4; length _yearlow _yearhi $4; _yearlow=2000+_ix; _ixp1=_ix+1; _yearhi=2000+_ixp1; PerNo=PerNo+1; Period=_yearlow||' to '||_yearhi; StartPop=est(_ix,_idemog); EndPop=est{_ixp1,_idemog}; _starttot=est{_ix,1}; _endtot=est{_ixp1,1}; link trendcode; end; end; *---the _idemog loop in which we ouput a set of trends for for each of the specified demographic categories-; *----We could "blank out" the est array here but it should not be necessary-------------------------; end; *---last.year processing---; return; trendcode: Change=EndPop - StartPop; if StartPop then PctChange=100*Change/StartPop; else PctChange=.; PctStart=StartPop*100/_starttot; PctEnd=EndPop*100/_endtot; if _periodlen ne . and StartPop then do; AnnualizedChange=Change/_periodLen; AnnualizedPctChange= 100*((Endpop/StartPop)**(1/_periodLen)-1); end; else do; AnnualizedChange=.; AnnualizedPctChange=.; *---why repeat what is already shown as the value for the 1-year interval?-; end; output; if &debug then if length(county)=2 then put / _all_; return; run; *---and now concatenate to create the final national dataset----; %macro setref(state,stab); &stab.trends %mend setref; data nchsbri.ustrends(label="Pop Trends 1990 to &latestyear for U.S. states and counties" index=(state)); set ustottrends %dostates(n=51,mac=setref) open=defer; run; proc freq data=nchsbri.ustrends; tables state sumlev demographic ; tables PerNo*period/list; format state $state. demographic $demog.; title2 "Freq Reports on nchsbri.ustrends"; run; /* =======================Begin comment================ ods listing close; ***ods pdf file="&pgm..pdf" style=sasweb title="My Report" ; ods tagsets.tableeditor file="&pgm..tagsets.html" style= sasweb options(banner_color_even="dedede" pageheight="600" pagewidth="95%" frozen_headers="no" zoom="80%" ); **** autofilter="yes" filter_cols="1,2,3" autofilter_width="7em" ; %let stab=mo; title2 "Population Trends for Missouri and Selected Counties: 1990 to 2006"; footnote h=1 c=blue "From setup in &pgm..sas in popests/Tools library"; options nodate missing=' ' pageno=1; footnote2 h=1 c=gray "Run on &sysdate at &systime"; footnote3 h=1 c=green "Using tableeditor tagset"; proc print data=&stab.trends(drop=sumlev state) split="/" ; where county in ('29 ','29019','29183','29077','29510') and demographic in('01','04','07','09','13'); *by County Demographic; id county demographic; label county="Geographic Area" demographic='Demographic Group' PctChange="% Change" AnnualizedChange="Annualized/ Change" AnnualizedPctChange="Annualized/% Change"; format county $county. demographic $demog. ; format period $char20.; var period StartPop--AnnualizedPctChange; run; ods tagsets.tableeditor close; ======================End comment================== */