/* 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, t2.CD116 LABEL="Congressional district code (116th Congress)" AS CD116, t2.CD117 LABEL="Congressional district code (117th Congress)" AS CD117, t2.CD118 LABEL="Congressional district code (118th Congress)" AS CD118, t2.SLDU22 LABEL="State legislative district, upper (2022)" AS SLDU22, t2.SLDL22 LABEL="State legislative district, lower (2022)" AS SLDL22, t2.SLDU18 LABEL="State legislative district, upper (2018)" AS SLDU18, t2.SLDL18 LABEL="State legislative district, lower (2018)" AS SLDL18, t1.VTD20, t1.ZCTA, t1.HSA19, t1.HRR19, t1.AIANNH, t1.MOLibrary, t1.IntPtLat, t1.IntPtLon, t1.LandSQMI, t1.AreaSQMI, t1.pop20, t1.HUs20 FROM mable22.&stab._blocks t1 LEFT JOIN mable22.updated_legislative_districts 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; %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(05);