x cd /pub/data/sf12010x/Tools; %let pgm=create_us_datafiles; filename pgm "&pgm..sas"; *----Generate the sf12010x.usXXXX data sets by concatenating or aggregating the state data sets. PR excluded. See also create_usmcds.sas in this same directory. jgb, 8-25-11. Rerun 8-31-11 to redo all sets. ---; libname sf12010x '/pub/data/sf12010x'; title "Create US Data Sets: &pgm"; libname user '/SAS_temp/user'; %macro setref(state,stab); sf12010x.&stab.selectedinv %mend setref; data sf12010x.usstcnty(index=(state)); set %dostates(n=51,mac=setref) open=defer; where sumlev in ('040','050'); run; proc means data=sf12010x.usstcnty n sum maxdec=0; title2 "usstcnty"; var totpop; class sumlev state; format state $state.; run; /* ========================begin comment==================================== data sf12010x.ustracts(index=(state)); set %dostates(n=51,mac=setref) open=defer; where sumlev ='140'; run; data sf12010x.uscousubs(index=(state)); *---This replaces what we previously named usmcds---; set %dostates(n=51,mac=setref) open=defer; where sumlev ='060'; run; proc means data=sf12010x.ustracts n sum maxdec=0; title2 "ustracts"; var totpop; class sumlev state; format state $state.; run; *=========================*========================*======================*=================*; data sf12010x.uszips871(index=(state)); set %dostates(n=51,mac=setref) open=defer; where sumlev='871'; run; proc means data=sf12010x.uszips871 n sum maxdec=0; var totpop; class state; format state $state.; title2 "uszips871"; run; *=========================*========================*======================*=================*; data sf12010x.uscdslds(index=(state) label="US 111th CD and 2009 State Leg Districts"); set %dostates(n=51,mac=setref) open=defer; where sumlev in ('500','610','620'); run; proc means data=sf12010x.uscdslds n sum maxdec=0; var totpop; class state sumlev; format state $state.; title2 "uscdslds"; run; *=========================*========================*======================*=================*; data sf12010x.usplaces(index=(state) label="Complete US places, any size"); set %dostates(n=51,mac=setref) open=defer; where sumlev ='160'; run; proc means data=sf12010x.usplaces n sum maxdec=0; var totpop; class state; format state $state.; title2 "usplaces"; run; *=========================*========================*======================*=================*; data sf12010x.usschools(index=(state) label="US School Districts, all types"); set %dostates(n=51,mac=setref) open=defer; where sumlev in ('950','960','970'); run; proc means data=sf12010x.usschools n sum maxdec=0; var totpop; class state sumlev ; format state $state.; title2 "usschools"; run; ==========================end comment====================================== */ *=========================*========================*======================*=================*; data _aggin; set %dostates(n=51,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--AvgSizeRenter , 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_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 ,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 ,debug=1) run; data sf12010x.usregdiv(label='US Totals + Regions & Divisions'); length SumLev $3 Geocode $16 Areaname $32; set aggout; select (_lvl_); when(1) do; SumLev='030'; geocode=division; Areaname="U.S. Division " ||division; end; when(2) do; SumLev='020'; geocode=Region; Areaname="U.S. Region "||region; end; when(99) do; SumLev='010'; geocode=' '; Areaname='U.S. Totals'; end; end; drop _: ; run; proc sort; by sumlev; run; proc print data=sf12010x.usregdiv; var _character_ totpop totpop00 PopChange PctPopChange; title2 "usregdiv"; run;