x cd /pub/data/popests/Tools; %let pgm=cnvt_nchs_bridged; filename pgm "&pgm..sas"; *---This setup was used to convert the 2005 thru 2009 vintage data. See setup in cnvt_nchs_bridged_201x.sas for the current setup (used during the decade 2010-2019). jgb, comment added and new module being coded 10-23-12. --; *---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. Creates datasets such as popests.monchsbridged20xx . John Blodgett, OSEDA under contract with Missouri Census Data Center. Coded 11-29-05. Revised for data thru 2005, 8-28-06, jgb. Revised for data thru 2006, 8-20-07, jgb. Revised for data thru 2007, 9-10-08, jgb Revised for data thru 2008, 9-08-09, jgb For v2008 we have 2 files with multiple years of estimates. Revised for data thru 2009, 9-01-10, jgb For v2009 we have 10 files, 1 for each year of estimates. NOTE: This job creates the input which is used by setup nchsbridged_sumry.sas to create the nchsbridgedCCxx_sumary SAS data sets which are used by the estimates_by_age web app. ---*; title "&pgm : Convert Custom Pop Estimates from NCHS with 'Bridged' Race Cats by Single Yrs"; libname popests '/pub/data/popests'; libname nchsbri '/pub/data/popests/nchsbri'; %let lastyr=2009; %let lyr=%substr(&lastyr,3,2); *filename indata pipe "unzip -p ../rawdata/pcen_v&lastyr..zip pcen_v&lastyr..txt"; *---for 2004 data--; *filename indata pipe "unzip -p ../rawdata/pcen_v&lastyr..zip pcen_v&lastyr..txt"; *---for 2006, 2007 data--; *filename indata1 pipe "unzip -p ../rawdata/pcen_v&lastyr._y0004.txt.zip pcen_v&lastyr._y0004.txt"; *---for 2008 data--; *<====; *filename indata2 pipe "unzip -p ../rawdata/pcen_v&lastyr._y0508.txt.zip pcen_v&lastyr._y0508.txt"; *---for 2008 data--; *filename indata pipe "unzip -p ../rawdata/pcen_v&lastyr..zip pcen_v&lastyr..txt"; *---for 2006, 2007 data--; *filename indata (indata1 indata2); *--2008 data only--; %macro filenams; %*---for 2009 (vintage) data--; %do i=0 %to 9; filename indata&i pipe "unzip -p ../rawdata/pcen_v&lastyr._y0&i..txt.zip pcen_v&lastyr._y0&i..txt"; %end; %mend; %filenams ; %macro doit(stfips,stab); %let dataset=nchsbri.&stab.nchsbridged20xx; data &dataset (label="Pop Ests from NCHS by Single Yrs of Age, Bridged Race, Sex and Hispanic, 2000-&lastyr"); %if &lastyr le 2007 %then %do; infile indata stopover; length State $2 County $5 Age $2 Race $1 Sex Hispanic $1 PopJl00 - PopJl&lyr 4; input _vintage $1-4 State $5-6 @; if _n_=1 then do; if _vintage ne "&lastyr" then do; put "Value of Vintage field does not match lastyr program parm (&lastyr)" _vintage=; put "Program is aborting"; abort abend; end; end; if state > "&stfips" then stop; *<================================; if state="&stfips"; input _co3 $7-9 @10 Age $char2. _racesex 12 Hispanic $13 (PopJl00 - PopJl&lyr)(8.); %end; %else %if &lastyr=2008 %then %do; %*--with vintage 2008 we get 2 files, ests from 2000 to 2004 and the 2nd with 2005 to latest--; infile indata1 stopover; length State $2 County $5 Age $2 Race $1 Sex Hispanic $1 PopJl00 - PopJl&lyr 4; input _vintage $1-4 State $5-6 @; if _n_=1 then do; if _vintage ne "&lastyr" then do; put "Value of Vintage field does not match lastyr program parm (&lastyr)" _vintage=; put "Program is aborting"; abort abend; end; end; if state > "&stfips" then stop; *<================================; if state ne "&stfips" then do; infile indata2; input; end; *--flush the record on companion input file--; if state="&stfips"; *---We read the ids from the indata1 file and then selected codes from indata2 to check that we are in synch--; input _co3 $7-9 @10 Age $char2. _racesex 12 Hispanic $13 (PopJl00 - PopJl04)(8.); infile indata2; input _co3ck $7-9 _ageck $char2. @14 (PopJl05 - PopJl&lyr)(8.); if _co3 ne _co3ck or Age ne _ageck then do; put '****County codes are not in synch....you probably need to try a different approach **** ' _n_= state= _co3= _co3ck= age= _ageck=; abort abend; end; %end; %else %if &lastyr=2009 %then %do; *---vintage 2009 requires us to read 10 files, 1 estimate per file/year---; infile indata0; length State $2 County $5 Age $2 Race $1 Sex Hispanic $1 PopJl00 - PopJl&lyr 4; input _vintage $4. _estyear $4. _cols9_17 $char9. @9 State $2. _co3 $3. Age $char2. _racesex $1. Hispanic $1. PopJL00 8.; if _vintage ne '2009' then abort abend; if _estyear ne '2000' then abort abend; if state > "&stfips" then stop; *<================================; %local i; %do i=1 %to 9; infile indata&i stopover; if state="&stfips" then do; input _vintage $4. +3 _estyear $1. _cols9_17ck $char9. @18 popJL0&i 8. ; if _vintage ne '2009' then abort abend; if _estyear ne "&i" then abort abend; if _cols9_17ck ne _cols9_17 then abort abend; end; else input; *--just flush the record--; %end; if state ="&stfips"; %end; County=State||_co3; if substr(age,1,1)=' ' then substr(age,1,1)='0'; if _racesex in ( 1, 3, 5, 7) then Sex='1'; else Sex='2'; if _racesex le 2 then Race='1'; else if _racesex le 4 then race='2'; else if _racesex le 6 then race='3'; else race='4'; *---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 popjl00='Pop Estimate July, 2000' popjl01='Pop Estimate July, 2001' popjl02='Pop Estimate July, 2002' popjl03='Pop Estimate July, 2003' popjl04='Pop Estimate July, 2004' popjl05='Pop Estimate July, 2005' popjl06='Pop Estimate July, 2006' popjl07='Pop Estimate July, 2007' popjl08='Pop Estimate July, 2008' popjl09='Pop Estimate July, 2009'; *<======================ADD 1 line each year==; drop _:; run; %if &state=29 %then %do; %*---make a copy of the missouri data in the main directory--; data popests.monchsbridged20xx; set nchsbri.monchsbridged20xx; run; %end; proc print data=&dataset; where 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; %mend doit; options mprint; options NOmprint; /* ========================begin comment==================================== %dostates(02 06); %dostates(10 12,names=1,msgs=1,debug=1); %dostates(01 04 05 08 09 11 13 15 16 18 19 21 22 23 24 25 27 28 30,names=1,msgs=1,debug=1); %dostates(20 26 29 36 48,names=1,msgs=1); %dostates(31 32 33 34 35 37 38 39 40 41 42 44 45 46 47 49 50 51 53 54 55 56,names=1); ==========================end comment====================================== */ %dostates(12 17);