x cd /pub/data/popests/Tools; %let pgm=cnvt_nchs_bridged2010cen; 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-10 numbers (2010 Census). Creates dataset popests.usnchsbridged2010cen. 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 ../census_0401_2010.txt"; filename indata "../nchsbri/census_0401_2010.txt"; %let dataset=nchsbri.usnchsbridged2010cen; /* ========================begin comment==================================== data &dataset (label="Census 2010 Pop Ests from NCHS by Single Yrs of Age, Bridged Race, Sex and Hispanic" index=(state)); infile indata stopover ; length State $2 County $5 Age $2 Race $1 Sex Hispanic $1 Pop2010 5; input State $1-2 _co3 $3. Age $char2. _raceSex $1. Hispanic $1. pop2010 8.; 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. ---*; if _racesex in ('1','3','5','7') then Sex='1'; else if _racesex ne ' ' then Sex='2'; length _race $1; _Race=substr(_racesex,1,1); if _race in ('1','2') then Race='1'; else if _race in ('3','4') then Race='2'; else if _race in ('5','6') then Race='3'; else if _race in ('7','8') then Race='4'; else race=' '; label pop2010='4-1-2010 Pop'; drop _:; run; 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"; run; proc sql; create view nchsbri.monchsbridged2010cen as select * from usnchsbridged2010cen where state='29'; quit; ==========================end comment====================================== */ *--------------And now, create the _sumry version------------------------------------*; %*et 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.nchsbridged2010cen; data sumryin; set &dataset; output; County=State; output; keep State County Age Race Sex Hispanic pop2010; run; proc sort; by County Age; run; proc summary data=sumryin ; by county ; class age race sex hispanic; var pop2010; 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="Pop2010 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=pop2010; else _rnhest=0; select(Race); when ('1') do; White + pop2010; WhiteNH + _rnhest; end; when ('2') do; Black + pop2010; BlackNH + _rnhest; end; when ('3') do; AmInd + pop2010; AmIndNH + _rnhest; end; when ('4') do; AsianPI + pop2010; AsianPINH + _rnhest; end; end; *--when race is not blank it indicates a race*hispanic combination---; if HispanicIn='2' then Hispanic + pop2010; else NonHispanic + pop2010; end; else if Sex ne ' ' then do; if Sex='1' then Male + pop2010; else Female + pop2010; 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 '2010'; 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 usnchsbridged2010cen_sumry; index create state; quit;