/* Generate the mable18 views used in the geocorr 2018 web application. This program merges three datasets created in previously run setups. */ %include '/pub/sas/autoexec.sas'; options fmtsearch=(mable18t sasctlgs); options nosource nosource2 mprint mlogic nosymbolgen notes; *libname mable18 '/pub/data/mable18t'; libname mable18t '/pub/data/mable18t'; libname sf12010x '/pub/data/sf12010x' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; libname xxgeos '/pub/data/sf12010/xxgeos' access=readonly; /* * already did this ; proc format library=mable18; value $SC2Alph '00'=' ' 01-04='A' 05-08='B' 09-11='C' 12-13='D' 14-15='E' 16-17='F' 18='G' 19-20='H' 21-23='I'; value $alphasc a,A='Less than 200' b,B='200-999' c,C='1000-2499' d,D='2500-9999' e,E='10,000-24,999' f,F='25,000-99,999' g,G='100,000-249,999' h,H='250,000-999,999' i,I='1,000,000+' ' '='Not in a place'; run; */ /* *-- We begin by creating a slightly edited version of the georef.cbsaco15----*; data mable18t.cbsacos15alt(label="Edited to change two counties in AK and SD"); set georef.cbsacos15 ; fipco14=fipco; if fipco='51019' then do; *--We got the 6466 estimate value from our popests.ussc14 data set (value would not display via QuickFacts at Bureau site)-; popjl14=popjl14- 6466; output; *--This is the old defn without the Beford City pop which we subtract; fipco='51515'; county=fipco; popjl14=6466; output; *--this is the old Bedford (Independent) city---; end; else output; *--all other counties just copy as-is --*; keep state fipco cbsa metrodiv county csa cbsatype Year PopJL14 Central; ***NO! DO NOT rename cbsa=cbsa15 metrodiv=metrodiv15 csa=csa15 Central=Central15 cbsatype=cbsatype15; run; proc sort; by state fipco; run; */ %macro doit(state,stab); data cdslds2012; set corrlst.uscdslds2012; where state="&state"; length cnty $3; cnty=substr(county,3,3); run; *-- the corrlst set with hrr and hsa uses esriid instead of county tract and block. So we have to create a new version here ; data hsahrr&state; set corrlst.usblocks2hsahrr; length cnty $3 Tract $7 block $4; where state="&state"; cnty=substr(esriid,3,3); tract=substr(esriid,6,4)||'.'||substr(esriid,10,2); block=substr(esriid,12,4); run; proc sort; by state cnty tract block; run; *-- Create the block-level dataset. New for this cycle we include the XXblks10_2kgeos variables puma2k and pop2k so we do not have to access these data (stored in the mable14 data dir) as part of the view definition. ; *-- cnty not on the sf12010x so we create a subset with it added ; data sf1xv/view=sf1xv; set sf12010x.&stab.blocks(keep=state county tract block over65); length cnty $3; cnty=substr(county,3,3); drop county; run; proc sort data=sf1xv out=sf1x; by state cnty tract block; run; /* data mable18t.&stab.blks (sortedby=county tract block index=(county)); merge xxgeos.&stab.blkgeos mable14.&stab.blk10_2kgeos(in=inblks2 keep=state cnty tract blk puma2k TotPop2k rename=(blk=block TotPop2k=Pop2k)) sf1x(in=insf1) cdslds2012 (in=in2 where=(state="&state")) hsahrr&state(in=inhsahrr) %if &state=29 %then %do; mable14.moblk2libdist(in=in3 keep=state cnty tract block libdcode) %end; ; by state cnty tract block; *-- last cycle we had county instead of cnty. But county not on blk10_2kgeos set ; where cnty ne ' '; *-- occurs in the blk10_2kgeos sets for a dozen states *; if _n_=1 and state ne "&state" then do; put //'*******Dataset Problem: State Code read is ' state " but parm value specified is &state"; abort abend; end; *-- New this cycle: create the SDBest10, SDbesttype10 variables with a single type of school district code ; length SDbest10 $5 SDbesttype10 $1; *-- recode 2010 school districts changing 99999 to blanks. Need this for sdbest logic to work ; if sduni='99999' then sduni=' '; if sdelm='99999' then sdelm=' '; if sdsec='99999' then sdsec=' '; if sduni ne ' ' then do; sdbest10=sduni; sdbesttype10='u'; end; else if sdelm ne ' ' then do; sdbest10=sdelm; sdbesttype10='e'; end; else if sdsec ne ' ' then do; sdbest10=sdsec; sdbesttype10='s'; end; keep sdbest: ; *-- Recode CntySC and PlaceSC into 10 intervals with alpha codes ; CntySC=put(CntySC,$SC2Alph2.); PlaceSC=put(PlaceSC,$SC2Alph2.); format CntySC PlaceSC $alphasc.; keep cd113 ; *** sldl12 sldu12; *-- from corrlst.uscdslds2012 ; keep sldl12 sldu12; *<-- putting back for test 11-19-15 ; keep puma2k pop2k; *-- from mable14.&stab.blk10_2kgeos ; keep cntysc placesc; keep county tract block state cnty placefp cousubfp bg cd111 sldu sldl vtd zcta5 AreaSQMI LandSQMI Pop100 HU100 IntPtLat IntPtLon SDElm SDSec SDUni; *** TAZ; length placece $4 cousubce $3; keep placece cousubce; keep hsa hrr over65; length _arg $7 _arg2 $10; _arg=state||placefp; if placefp='99999' then placece='9999'; else placece=put(_arg,$fplccnv.); _arg2=county||cousubfp; cousubce=put(_arg2,$fmcdcnv.); label placece='Census Place Code' cousubce='Census County Subd. code'; length InPlace $1; *-- Indicates if in an incorporated place(1), a CDP(2) or not in a place(3). ; if placefp='99999' then InPlace='3'; else if placecc=:'C' then InPlace='1'; else InPlace='2'; keep InPlace; label Inplace='Indicates incorporated, CDP or not in a place'; keep necta nectadiv cnecta; label necta='New England City and Town Area 2010' nectadiv='NECTA Divsion 2010' cnecta='Combined NECTA 2010'; %if %index(09 23 25 33 44 50,&state) ne 0 %then %do; *-- We use to have the above keep statement as optional. ; %end; %if &state=29 %then %str(keep libdcode;); label Pop100='Total Pop, 2010 census' hu100='Total HUs, 2010 census'; rename Pop100=pop10 HU100=hus10; run; */ /* *-- already have these ; data mable18t.&stab.blks (sortedby=county tract block index=(county)); set mable18.&stab.blks; run; *-- already have these ; data mable18t.&stab.cocds1 (sortedby=county index=(county)); set mable18.&stab.cocds1; run; *-- already have these ; proc sort data=mable18t.&stab.tgrlnfaces; by cnty tract block; run; */ /* This view combines (merges) the block-level data from the block datasets, the TIGER/Line faces files, and the cocds1 county-level data. */ data mable18t.&stab.v/view=mable18t.&stab.v; merge mable18t.&stab.blks(in=inblks1) mable18t.&stab.tgrlnfaces(in=inblks3); by state cnty tract block; if first.cnty then set mable18t.&stab.cocds1(rename=(county=countyck)); if county ne countyck then do; put "Error: county code on &stab.cocds1 dataset does not match that on the blks datasets****" county= countyck=; stop; end; if placefp14=' ' then placefp14='99999'; *-- for consistency with placefp (2010) ; if placefp18=' ' then placefp18='99999'; *-- for consistency with placefp (2010) ; if cbsa10 ne '99999' and cbsa10 ne ' ' then do; CbsaSC10=put(CbsaSC10,$SC2Alph2.); format Cbsasc10 $alphasc. ; if cbsatype10=" " then do; length _cbsaname $80; _cbsaname=put(cbsa10,$cbsa40.); if index(_cbsaname,'Micropolitan') then cbsatype10='Micro'; else cbsatype10='Metro'; end; end; if not (inblks1 and inblks3) then do; _missingbdata+1; *-- we allow missing data for the 2k data. There are a few in each state. ; if _missingbdata le 5000 then put "Missing data for block: " inblks1= inblks3= cnty= tract= block=; else abort abend; end; drop countyck; drop _: ; run; *-- Write a record to end of cnvtlog.txt documenting what we just did. ; data _null_; set mable18t.&stab.blks (obs=3) nobs=_nobs; file "cnvtlog.txt" mod; if _n_=1 then put "Conversion for &stab&state complete on &sysdate at &systime . Census blocks processed: " _nobs; *put / _all_ / ; stop; run; %mend doit; /* begin comment ==================================== %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17); %dostates(18 19 20 21 22 23 24 25 26 27 28 29 30 31); %dostates(32 33 34 35 36 37 38 39 40 41 42); %dostates(44 45 46 47 48 49 50 53 54 55 56); %dostates(51); *-- found an error in MN (the CBSA code for Fairmont Micropolitan Area) so rerunning 2-25-16---; %dostates(27); *-- regenerating Arkansas (3-20-17) after finding problem with Hempstead co CBSA code. -; %dostates(05) ; ========================== end comment */ %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17); %dostates(18 19 20 21 22 23 24 25 26 27 28 29 30 31); %dostates(32 33 34 35 36 37 38 39 40 41 42); %dostates(44 45 46 47 48 49 50 51 53 54 55 56);