x cd /pub/data/popests/Tools; %let pgm=cnvt_nchs_bridged2kcen; filename pgm "&pgm..sas"; *---Read the custom single-year-of-age by "bridged" race by sex and hispanic estimates downloaded from NCHS web site and created for them by the Census Bureau. These are the 4-1-00 numbers (2000 Census). Creates dataset popests.usnchsbridged0400. John Blodgett, OSEDA under contract with Missouri Census Data Center. Coded 3-30-06 . ---*; title "&pgm : Convert 04-01-2000 Custom Pop pop2ks from NCHS with 'Bridged' Race Cats by Single Yrs"; libname nchsbri '/pub/data/popests/nchsbri'; filename indata pipe "unzip -p ../br040100"; %let dataset=nchsbri.usnchsbridged2kcen; /* =======================Begin comment================ data &dataset (label="Pop Ests from NCHS by Single Yrs of Age, Bridged Race, Sex and Hispanic, 4-1-2000" index=(state)); infile indata stopover; length State $2 County $5 Age $2 Race $1 Sex Hispanic $1 Pop2k 4; input State $1-2 _co3 $3. Race $1. Sex $1. Hispanic $1. Age $char2. pop2k 7.; County=State||_co3; if substr(age,1,1)=' ' then substr(age,1,1)='0'; *---Code values here are: Race: 1=white 2=black 3=American Ind etc 4=Asian PI. Sex: 1=male 2=female Hispanic: 1=non 2=hispanic. Age: 0= under 1 yr 1=1 yeuar old ... 85=85 and over. ---*; label pop2k='Pop Count 2K Census'; drop _:; run; proc sql; create view nchsbri.monchsbridged2kcen as select * from usnchsbridged2kcen where state='29'; quit; proc print data=&dataset; where state='29' and age='60' and race='1' and sex='1' and hispanic='1'; by state ; id county age race sex hispanic; title2 "Partial Listing of &dataset, MO Subset"; run; ======================End comment================== */ *--------------And now, create the _sumry version------------------------------------*; %let stab=mo; *<=========Ran it this way to generate the mo sumry dataset. Now we do it for the US.--; %let stab=us; %let dataset=nchsbri.&stab.nchsbridged2kcen; data sumryin; set &dataset; output; County=State; output; keep State County Age Race Sex Hispanic pop2k; run; proc sort; by County Age; run; proc summary data=sumryin ; by county ; class age race sex hispanic; var pop2k; types age*race*hispanic age*sex race*hispanic sex ; output out=sumryout sum= ; run; proc sort; by county age _type_; run; data &dataset._sumry(label="Pop2k Counts for &stab States & Counties by total & single yrs of age " index=(county)); length State $2; set sumryout(rename=(hispanic=hispanicIn)); retain SumLev ' '; by county age ; length Age_cohort1 Age_cohort2 $2 default=5; retain age_cohort1 age_cohort2; if first.county then if length(county)=2 then SumLev='040'; else SumLev='050'; array _count(*) Total Male Female White WhiteNH Black BlackNH AmInd AmIndNH AsianPI AsianPINH Hispanic NonHispanic; State=substr(county,1,2); if first.age then do _i=1 to dim(_count); _count{_i}=0; *--define the age_cohort variables which will facilitate aggregating to these intervals---; if age=' ' then age_cohort1=' '; else if age le '17' then age_cohort1='00'; else if age le '24' then age_cohort1='18'; else if age le '44' then age_cohort1='25'; else if age le '64' then age_cohort1='45'; else age_cohort1='65'; length _agec2 8; if age=' ' then age_cohort2=' '; else do; _agec2=int(input(age,2.)/5)*5; age_cohort2=put(_agec2,z2.); end; end; if Race ne ' ' then do; if hispanicIn='1' then _rnhest=pop2k; else _rnhest=0; select(Race); when ('1') do; White + pop2k; WhiteNH + _rnhest; end; when ('2') do; Black + pop2k; BlackNH + _rnhest; end; when ('3') do; AmInd + pop2k; AmIndNH + _rnhest; end; when ('4') do; AsianPI + pop2k; AsianPINH + _rnhest; end; end; *--when race is not blank it indicates a race*hispanic combination---; if HispanicIn='2' then Hispanic + pop2k; else NonHispanic + pop2k; end; else if Sex ne ' ' then do; if Sex='1' then Male + pop2k; else Female + pop2k; end; else do; _nerr+1; if _nerr=1 then put // '*****Logic Errors Found****** '; if _nerr le 10 then put / _all_; else abort abend; end; cklast: if last.age then do; Total=Male + Female; output; end; keep SumLev State county age age_cohort: Total White--AsianPINH Male Female Hispanic NonHispanic; retain Cenyr '2000'; label age_cohort1='Broad age Cohort: 0-17,...,65+' age_cohort2='5-yr Cohort: 0-4,...,85+'; label Cenyr='Census year' White='White Persons (bridged race)' AmInd='American Indian, Esk, Aleut (bridged race)' WhiteNH='White non-hispanic Persons (bridged race)' Black='Black Persons (bridged race)' BlackNH='Black non-hispanic Persons (bridged race)'; run; proc datasets library=nchsbri nolist; modify &dataset; index create state; modify &dataset._sumry; index create state; quit;