x cd /pub/data/dhc2020x/Tools; %let pgm=create_us_datafiles; filename pgm "&pgm..sas"; /* Generate the dhc2020x.usXXXX data sets by concatenating or aggregating the state data sets. */ %include '/pub/sas/autoexec.sas'; options notes source nosource2 nomprint nosymbolgen nomlogic compress=binary spool; libname dhc2020x '/pub/data/dhc2020x'; title "Create US Data Sets: &pgm"; %macro setref(state,stab); dhc2020x.&stab.selectedinv %mend setref; data dhc2020x.usstcnty(index=(state)); set %dostates(n=52, mac=setref) open=defer; where sumlev in ('040', '050'); run; data dhc2020x.ustracts(index=(state)); set %dostates(n=52, mac=setref) open=defer; where sumlev = '140'; run; data dhc2020x.uscousubs(index=(state)); set %dostates(n=52, mac=setref) open=defer; where sumlev = '060'; run; data dhc2020x.uszctas(index=(state)); set %dostates(n=52, mac=setref) open=defer; where sumlev = '871'; run; data dhc2020x.uscdslds(index=(state) label="US 116th congressional districts and 2018 state legislative districts"); set %dostates(n=52, mac=setref) open=defer; where sumlev in ('500', '610', '620'); run; data dhc2020x.usplaces(index=(state) label="Complete US places, any size"); set %dostates(n=52, mac=setref) open=defer; where sumlev = '160'; run; data dhc2020x.usschools(index=(state) label="US school districts, all types"); set %dostates(n=52, mac=setref) open=defer; where sumlev in ('950', '960', '970'); run; data _aggin; set %dostates(n=52, mac=setref) open=defer; where sumlev ='040'; * We failed to keep the region and division variables on these extracts so we have to use a format-table lookup ; length Region Division $1 _temp $2; _temp = put(state, $stdivr2.); Region = substr(_temp, 2, 1); Division = substr(_temp, 1, 1); keep state stab region division _numeric_; run; proc sort; by region division; run; %agg( setin=_aggin , setout=aggout, aggby=region division, idvars=, agglvl=2, vars= LandSQMI AreaSQMI TotPop--RentalVacrate , facvar= , dropvars=, grand=1, naggvars=0, nmeans=0 , nmwts=0 , means=PctPopChange PctMale PctFemale PopPSqmi PctAge0_4 PctAge5_9 PctAge10_14 PctAge15_17 PctAge18_19 PctAge20_24 PctAge25_34 PctAge35_44 PctAge45_54 PctAge55_64 PctAge65_74 PctAge75_84 PctOver85 PctAge15_19 PctAge18_24 PctAge25_44 PctAge45_64 PctUnder18 PctOver18 PctOver18_male PctOver18_female PctOver21 PctOver62 PctOver65 PctOver65_male PctOver65_female MedianAge PctOne_Race_total PctWhite1 PctBlack1 PctIndian PctAsian1 PctHawnPI1 PctOther1 PctMultRace PctWhite2 PctBlack2 PctIndian2 PctAsian2 PctHawnpi2 PctOther2 PctHispPop PctNon_Hispanic PctWhite_Non_Hisp PctHHpop PctHouseholder PctSpouse PctOppSexSpouse PctSameSexSpouse PctUnmarriedPartner PctOppSexPartner PctSameSexPartner PctChild PctOwnChild_under18 PctOther_Relatives PctNonrelatives PctFamilies PctFamilyKidsLT18 PctMarried_Couple PctMarrdCplKidsLT18 PctMaleHhldr PctSingleDads PctFemaleHhldr PctSingleMoms PctNonFamily_HHs PctMPartnerHHs PctOppSexMPrtnrHHs PctSameSexMPrtnrHHs PctUnmPartnerHHs PctOppSexUnmPrtnrHHs PctSameSexUnmPrtnrHHs PctLivingAlone PctHousehldrOver65 PctHHsIndvLT18 PctHHsIndvOvr65 PctGQpop PctInstitution_pop PctCorrectionalPop PctNursingHomePop PctOtherInstPop PctNonInstGQPop PctCollegeDorms PctMilitaryQtrs PctOthrNoninstGQPop PctOccupied_Units PctOwnerOccupied PctRenterOccupied PctVacantUnits PctVacantForRent PctVacantForSale PctSeasonal PctOwnerTot PctRenterTot OwnerVacrate RentalVacrate, meanwts=TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs tothhs TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop tot_units tot_units tot_units tot_units tot_units tot_units tot_units tot_units tot_units OwnerTot RenterTot, debug=1) run; data dhc2020x.usregdiv(label='US totals, regions, and divisions'); length SumLev $3 Geocode $16 Areaname $32; set aggout; select (_lvl_); when(1) do; SumLev='030'; geocode=division; Areaname="US Census Division "||division; end; when(2) do; SumLev='020'; geocode=Region; Areaname="US Census Region "||region; end; when(99) do; SumLev='010'; geocode=' '; Areaname='US Total'; end; end; drop _: ; run; proc sort; by sumlev; run; data dhc2020x.usregdiv; retain sumlev geocode region division ; set dhc2020x.usregdiv; run;