x cd /pub/data/sf12010x/Tools; %let pgm=create_us_zips860; filename pgm "&pgm..sas"; *----Generate the sf12010x.uszips860 data set by aggregating data in uszips871. Useful for merging with complete-ZCTA data from the ACS. jgb, 1-3-13. ---; libname sf12010x '/pub/data/sf12010x'; title "&pgm"; libname user '/SAS_temp/user'; libname georef '/pub/data/georef' access=readonly; *---Pull selected geographic info from the georef.zcta_master data set (such as zipname and primary state ---; data ziprefinfo; set georef.zcta_master(where=(psf=1) keep=psf zcta5 state pctstate stab fipco fipco2 county pctcnty ZIPName ZIPTotPop Altzips Naltzips); label fipco='Primary County' state='Primary state'; label AltZIPs='Alternate ZIP codes associated with this ZCTA' NaltZIPs='# of alternative ZIP codes'; label pctstate='% of ZCTAs total pop in primary State'; drop psf; run; proc sort data=ziprefinfo; by zcta5; run; *---Aggregate the zip-within-state data to get totals for the entire zip (ZCTA)---*; proc sort data=sf12010x.uszips871 out=_aggin; by zcta5 ; run; %agg(setin=_aggin , setout=aggout, aggby=zcta5, idvars=, agglvl=1, vars= LandSQMI AreaSQMI IntPtLat IntPtLon TotPop--AvgSizeRenter , facvar= , dropvars=, grand=0, 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_59 PctAge60_64 PctAge65_74 PctAge75_84 PctOver85 MedianAge PctUnder18 PctAge18_24 PctAge25_44 PctAge45_64 PctOver62 PctOver65 PctOver18 PctOver18_male PctOver18_female PctOver21 PctAge15_19 PctAge18_24 PctOver65_male PctOver65_female PctOne_Race_total PctWhite1 PctBlack1 PctIndian PctAsian1 PctHawnPI1 PctOther1 PctMultRace PctWhite2 PctBlack2 PctIndian2 PctAsian2 PctHawnpi2 PctOther2 PctHawaiian PctGuam_or_Cham PctSamoan PctOther_Pac_Islndr PctAsian_indian PctChinese PctFilipino PctJapanese PctKorean PctVietnamese PctOtherAsian PctHispPop PctMexican PctPuertoRican PctCuban PctOtherHispanic PctNon_Hispanic PctWhite_Non_Hisp PctHHpop PctHouseholder PctSpouse PctChild PctOwnChild_under18 PctOther_Relatives PctNonrelatives PctNonreltvUnder18 PctNonreltvOver65 PctUnmarriedPartner PctFamilies PctFamilyKidsLT18 PctMarried_Couple PctMarrdCplKidsLT18 PctFemaleHhldr PctSingleMoms PctNonFamily_HHs PctUnmPartnerHHs PctSameSexPrtnrHHs PctLivingAlone PctHousehldrOver65 PctHHsIndvLT18 PctHHsIndvOvr65 AvgHHoldSize AvgFamilySize PctGQpop PctInstitution_pop PctCorrectionalPop PctNursingHomePop PctOtherInstPop PctNonInstGQPop PctCollegeDorms PctMilitaryQtrs PctOthrNoninstGQPop PctOccupied_Units PctOwnerOccupied PctRenterOccupied PctVacantUnits PctVacantForRent PctVacantForSale PctSeasonal PctOwnerTot PctRenterTot OwnerVacrate RentalVacrate PctPopInOwnerUnits PctPopInRentedUnits AvgSizeOwner AvgSizeRenter IntPtLat IntPtLon ,meanwts=TotPop00 TotPop TotPop landsqmi 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 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 families TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop TotPop tot_units Occupied_units Occupied_units tot_units tot_units tot_units tot_units tot_units tot_units OwnerTot RenterTot TotPop TotPop OwnerOccupied RenterOccupied AreaSQMI AreaSQMI ,debug=1) run; data sf12010x.uszips860; retain SumLev '860'; merge ziprefinfo (in=inzipref) aggout(in=insf1data); by zcta5; if not (inzipref and insf1data) and totpop > 0 then do; _nerr +1; put '**ZCTA not found in either zipref or sf1: ' inzipref= insf1data= zcta5= totpop=; if _nerr ge 250 then abort abend; if not insf1data then delete; end; else if (zipTotPop ne TotPop) then do; put '***ZCTA total pop from SF1 not matching that on zcta_master*** ' zcta5= totpop= ziptotpop=; _nerr+1; end; drop ZIPTotPop; drop _: ; format LandSQMI AreaSQMI 7.2; run; proc contents data=sf12010x.uszips860 ; run;