x cd /pub/data/dhc2020x/Tools; %let pgm=cnvt_dhc2020x; filename pgm "&pgm..sas"; /* Create a series of standard extract data sets for one or more specified states using standard census geographies. */ %include '/pub/sas/autoexec.sas'; options nonotes source nosource2 nomprint nosymbolgen nomlogic compress=binary spool; libname dhc2020 "/pub/data/dhc2020" access=readonly; libname dhc (dhc2020); libname dhc2020x '/pub/data/dhc2020x'; libname dhcx (dhc2020x); libname sf12010x '/pub/data/sf12010x'; libname blkrel20 '/pub/data/blkrel20' access=readonly; title "&pgm: Create dhc2020x extract datasets from dhc2020 datasets"; /* * Only need to do this once ; options nonumber nodate orientation=landscape nocenter; ods pdf file="../Variables.pdf" style=plateau; * ods html file='../Variables.html' style=plateau; * THIS WILL OVERWRITE EXISTING variables.html FILE WITH ANY SUBSEQUENT EDITS! ; ods listing close; proc print data=dhcx.Variables label; where pctflag=0 or UnivVar=' '; * do not show the Pct variables unless they are stand-alone ; by table notsorted universe notsorted; id name; var label--comment UnivVar WtVar lvl; format label $char.; title 'Metadata for the dhc2020x filetype (partial listing of variables dataset)'; footnote 'Note: Universe variable is denominator used to create corresponding pct variable'; title2 "Revised as of &sysdate &systime"; run; ods pdf close; ods html close; */ %macro doit(state, stab); %let ustab = %upcase(&stab); %*goto selectedinv; * <======== DEBUG: skip already-tested portions of the code ; * BLOCKS ; data blockpops10; set blkrel20.&stab.poptrend2020blks(rename=(blk=block) drop=totpop tothus); length _geocode $15 ; _geocode = county||substr(tract, 1, 4)||substr(tract, 6, 2)||block; run; proc sort force; by _geocode; run; data blocks2020; set dhc2020.&stab.blocks; length _geocode $15 ; _geocode = trim(esriid); run; proc sort force; by _geocode; run; data &stab.blocks; length SumLev $3 esriid $15 areaname $10 ; merge blocks2020(in=in2020) blockpops10(in=in2010); by _geocode; if in2020; %include 'variables_no_PCT.sas'; keep logrecno geoid esriid sumlev areaname state stab county tract blkgrp block cbsa csa metdiv ua place cousub necta nectadiv cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni ; keep intptlat intptlon lsadc landsqmi areasqmi ; keep TotPop TotPop10--RentalVacrate; drop _: ; run; data dhcx.&stab.blocks (label="Census block summaries for &statenm" index=(county) outrep=LINUX_X86_64); retain SumLev esriid areaname logrecno geoid state stab county tract cousub place blkgrp block cbsa csa metdiv necta nectadiv ua cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni intptlat intptlon lsadc landsqmi areasqmi TotPop TotPop10 PopChange PctPopChange ; set &stab.blocks; run; %bgs: * BLOCK GROUPS *; data bgpops10; set blkrel20.&stab.poptrend2020bgtrcopl(where=(sumlev='150') drop=totpop tothus); length _geocode $12 ; _geocode = county||substr(tract, 1, 4)||substr(tract, 6, 2)||bg; run; proc sort force; by _geocode; run; data bgs2020; set dhc2020.&stab.bgs150; length _geocode $12 ; _geocode = trim(esriid); run; proc sort force; by _geocode; run; data &stab.bgs150; length SumLev $3 esriid $12 areaname $14 ; merge bgs2020(in=in2020) bgpops10(in=in2010); by _geocode; if in2020; %include 'variables_no_PCT.sas'; keep logrecno geoid esriid sumlev areaname state stab county tract blkgrp cbsa csa metdiv ua place cousub necta nectadiv cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni ; keep lsadc LandSQMI AreaSQMI IntPtLat IntPtLon ; keep TotPop TotPop10--RentalVacrate; drop _: ; run; data dhcx.&stab.bgs150 (label="Block group level (150) summaries for &statenm" index=(county) outrep=LINUX_X86_64); retain SumLev esriid areaname logrecno geoid state stab county tract cousub place blkgrp block cbsa csa metdiv necta nectadiv ua cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni intptlat intptlon lsadc landsqmi areasqmi TotPop TotPop10 PopChange PctPopChange ; set &stab.bgs150; run; %selectedinv: * SELECTED INVENTORY ; %let invlevls = %str('040', '050', '060', '155', '160', '320', '420', '500', '610', '620', '860', '871', '950', '960', '970'); data tractpops10; set blkrel20.&stab.poptrend2020bgtrcopl(where=(sumlev='140') drop=totpop tothus); length _geocode $11 ; _geocode = county||substr(tract, 1, 4)||substr(tract, 6, 2); keep _geocode TotPop10; run; data otherpops10; set sf12010x.&stab.selectedinv(where=(state="&state" and sumlev in (&invlevls))); length _geocode $11 ; _geocode = trim(esriid); keep _geocode TotPop; rename TotPop=TotPop10; run; data invpops10; set tractpops10 otherpops10 ; run; proc sort force; by _geocode; run; data inv2020; set dhc2020.&stab.inventory(where=(sumlev in ('140', &invlevls) and geocomp='00')); length _geocode $11 ; _geocode = trim(esriid); run; proc sort force; by _geocode; run; data &stab.selectedinv; length SumLev $3 esriid $11 areaname $90 ; merge inv2020(in=in2020) invpops10(in=in2010); by _geocode; if in2020; %include 'variables_with_PCT.sas'; keep logrecno geoid esriid sumlev areaname state stab county tract cbsa csa metdiv ua place cousub necta nectadiv cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni ; keep lsadc LandSQMI AreaSQMI IntPtLat IntPtLon ; keep TotPop TotPop10--RentalVacrate; drop _: ; run; proc sort force; by geoid; run; data dhcx.&stab.selectedinv(label="Selected inventory summaries for &statenm" index=(sumlev) outrep=LINUX_X86_64); retain SumLev esriid areaname logrecno geoid state stab county tract cousub place cbsa csa metdiv necta nectadiv ua cd116 sldu18 sldl18 vtd zcta sdelm sdsec sduni intptlat intptlon lsadc landsqmi areasqmi TotPop TotPop10 PopChange PctPopChange ; set &stab.selectedinv; run; %endmac: %mend doit; /* %dostates( 10 , names=1 ); * testing with DE ; %dostates( 01 02 04 05 06 , names=1 ); %dostates( 08 09 10 11 12 13 15 , names=1 ); %dostates( 16 17 18 19 20 21 , names=1 ); %dostates( 22 23 24 25 26 27 28 29 30 , names=1 ); %dostates( 31 32 33 34 35 36 37 38 , names=1 ); %dostates( 39 40 41 42 44 45 46 , names=1 ); %dostates( 47 48 49 50 51 , names=1 ); %dostates( 53 54 55 56 , names=1 ); */ %dostates( 72 , names=1 );