/* Generate the mable22 views used in the geocorr 2022 web application. This program merges two datasets created in previously run setups. */ %include '/pub/sas/autoexec.sas'; options fmtsearch=(mable22 sasctlgs); options source source2 mprint mlogic symbolgen notes; libname mable22 '/pub/data/mable22'; %macro doit(state,stab); * --------------------- North Carolina only ----------------------; PROC SQL; CREATE TABLE mable22.&stab._blocks AS SELECT t1.GEOID, t1.State, t1.County, t1.CountySC, t1.County3, t1.CouSub20, t1.Place, t1.PlaceSC, t1.InPlace, t1.Tract, t1.BlockGroup, t1.Block, t1.NECTA, t1.NECTADiv, t1.CNECTA, t1.ConsCity, t1.SDElem20, t1.SDSec20, t1.SDUni20, t1.SDBest20, t1.SDBestType20, t1.PUMA12, t1.PUMA22, t1.CD116, t2.CD117 LABEL="Congressional district code (117th Congress)" AS CD117, t1.CD118, t1.SLDU22, t1.SLDL22, t1.SLDU18, t1.SLDL18, t1.VTD20, t1.ZCTA, t1.HSA19, t1.HRR19, t1.MOLibrary, t1.IntPtLat, t1.IntPtLon, t1.LandSQMI, t1.AreaSQMI, t1.pop20, t1.HUs20 FROM mable22.&stab._blocks t1 LEFT JOIN mable22.nc117 t2 ON (t1.GEOID = t2.GEOID); QUIT; data mable22.&stab.v/view=mable22.&stab.v; set mable22.&stab._blocks(in=inblks1) ; by county ; if first.county then set mable22.&stab._counties(rename=(county=countyck)); if county ne countyck then do; put "Error: county code on &stab._counties dataset does not match that on the blocks datasets****" county= countyck=; stop; end; if not (inblks1) then do; _missingbdata+1; *-- we allow missing data for the 2020 data. There are a few in each state. ; if _missingbdata le 100 then put "Missing data for block: " inblks1= county= 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 mable22.&stab._blocks (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; /* * --------------------- all the other states ----------------------; data mable22.&stab._blocks; retain GEOID State County CountySC County3 CouSub20 MCD Place PlaceSC InPlace Tract BlockGroup Block NECTA NECTADiv CNECTA ConsCity SDElem20 SDSec20 SDUni20 SDBest20 SDBestType20 PUMA12 PUMA22 CD116 ; set mable22.&stab._blocks; where state ^= '37' ; * Exclude NC ; length CD117 $ 2 ; CD117 = CD116 ; run; data mable22.&stab.v/view=mable22.&stab.v; set mable22.&stab._blocks(in=inblks1) ; by county ; if first.county then set mable22.&stab._counties(rename=(county=countyck)); if county ne countyck then do; put "Error: county code on &stab._counties dataset does not match that on the blocks datasets****" county= countyck=; stop; end; if not (inblks1) then do; _missingbdata+1; *-- we allow missing data for the 2020 data. There are a few in each state. ; if _missingbdata le 100 then put "Missing data for block: " inblks1= county= 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 mable22.&stab._blocks (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; * -------- fix the variable order -------------------------; data mable22.&stab._blocks; retain GEOID State County CountySC County3 CouSub20 MCD Place PlaceSC InPlace Tract BlockGroup Block NECTA NECTADiv CNECTA ConsCity SDElem20 SDSec20 SDUni20 SDBest20 SDBestType20 PUMA12 PUMA22 CD116 CD117 CD118 SLDU22 SLDL22 SLDU18 SLDL18 VTD20 ZCTA HSA19 HRR19 MOLibrary IntPtLat IntPtLon LandSQMI AreaSQMI pop20 HUs20 ; set mable22.&stab._blocks; 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 72); %dostates(09 10); %dostates(n=52); ========================== end comment */ %dostates(37);