x cd /pub/data/popests/Tools; %let pgm=casrh_cnvt20yy; filename pgm "&pgm..sas"; *********NOT the current convert module. See casrh_cnvt201x.sas ****************; *--Convert county and state level age-sex-race-hispanic origin pop estimates. John Blodgett, OSEDA, U of Mo Outreach & Extension Under contract with the Missouri Census Data Center 9/03 --*; /* Update History Sep. 16, 2003: Begin work. Sep. 29, 2004: Adapting to run for the data released 9-29-04 with ests thru 2003. Oct. 04, 2004: Adding step to create state level summaries in moilkscasrh&yr dataset. */ %let temp=; ***temp; *<====change to null value when data is no longer embargoed and is moved to popests directory--; %let year=2003; %let yr=%substr(&year,3,2); libname popests "/pub/data/popests/&temp"; libname georef '/pub/data/georef' access=readonly; *--Load value-label formats---; %include 'casrh_formats.sas'; *<====requires that these be in the current directory, which for us is Tools-; x cd /pub/data/popests/&temp; *<====; %macro doit(state,stab); *filename in pipe "unzip -p coarsh_ss.zip coarsh_&state..txt"; filename in "&stab.casrh&yr..csv"; data popests.&stab.casrh&yr(label="Pop Ests by County, Age, Sex, Race, Hispanic: 2000 - &year" compress=no); infile in dsd missover firstobs=2; %if &year=2002 %then %do; length SumType $4 State $2 Fipco County $5 Reg $1 Div $1 _ctyname $64 _stname $64 Age $2 Sex $1 Race $2 Hispanic $1 %end; %else %do; %*--this line corresponds to the layout used in 2004, year parm 2003--; length SumType $4 State $2 Fipco County $5 Reg $1 Div $1 _stname $64 _ctyname $64 Age $2 Sex $1 Race $2 Hispanic $1 Cen2k EstBase %end; %do yy=2000 %to &year; popest_&yy %end; 5; input County -- popest_&year; label Cen2k='Census 2000 count' EstBase='Estimates Base 2000'; if popest_&year=. then do; _Nbad+1; if _nbad le 25 then put 'Problem with this input line: ' / _infile_ / _all_; else abort abend; end; if county ne lag(county) then set georef.cbsacos(keep=county cbsa cbsatype) key=county; State=substr(county,1,2); fipco=county; format county $county.; *---Recode so that where value of 0 indicates NA we assign a missing value---; if age='0' then age=' '; if sex='0' then sex=' '; if race='0' then race=' '; if hispanic='0' then hispanic=' '; if length(age)=1 and age ne ' ' then age='0'||age; if length(race)=1 and race ne ' ' then race='0'||race; SumType=' '; *--Each of the 4 characters of SumType indicate whether a specific category is being utilized on this obs. In the case of the 3rd character, the Race indicator, we use a lowercase r to indicate a single race alone (or multi-race) and an uppercase R to indicate an "alone or in combination" category.--; if age ne ' ' then substr(SumType,1,1)='a'; if sex ne ' ' then substr(SumType,2,1)='s'; if ('01' le race le '06') then substr(SumType,3,1)='r'; else if race >= '07' then substr(Sumtype,3,1)='R'; if hispanic ne ' ' then substr(SumType,4,1)='h'; Sumtype=compress(Sumtype); drop _:; *<---drop all variables that start with an underscore--; ***** if substr(county,3,3) gt '005' then stop; run ; proc sort; by county sumtype; run; proc datasets library=popests nolist; modify &stab.casrh&yr; index create county; index create Sumtype; index create typeco=(County Sumtype); quit; filename in clear; proc freq data=popests.&stab.casrh&yr; *--These value label format codes are stored in the casrh_formats.sas module in this directory--; format Sumtype $sumtype. age $age. race $race. sex $sex. hispanic $hispani. ; format cbsa $cbsa.; table SumType Age Race sex hispanic /missing; table cbsa county; **weight popest_&year; run cancel; *<========; %mend doit; options mprint; /*<=========================Comment out===================================== %doit(29,mo) ; %doit(20,ks) ; %doit(17,il) ===========================End commented out================================ */ *------------------------Phase II: Create state summaries dataset------------------*; data aggin_casrh/view=aggin_casrh; length stab $2 SumLev $3 Areaname $24; retain SumLev '040'; set popests.ilcasrh&yr popests.kscasrh&yr popests.mocasrh&yr; drop county fipco cbsa: ; stab=put(state,$fipstab2.); areaname=put(state,$state.); run; proc means data=aggin_casrh nway missing noprint sum ; by state; id SumLev Areaname stab; class SumType age sex race hispanic; var Cen2k EstBase popest: ; output out=popests.moilkscasrh&yr(drop=_type_ _freq_) sum= ; run; proc freq data=popests.moilkscasrh&yr ; tables state*areaname/list; table stab*SumType; title2 "Freqs on the popests.moilkscasrh&yr dataset"; run;