x cd /pub/data/acs2012/Tools; %let pgm=usbgprofiles; filename pgm "&pgm..sas"; /*--Generate acs.usbgs5yr J. Blodgett, OSEDA, Jan, 2014 . Input data set acs.usbgstemp was created by mcdcprofiles5yr.sas. The acs.newbgvars5yr was created by job newbgvars.sas . Data set acs.usbgtemp was deleted 2/14. Special rerun 2-3-14 to fix Vintage variable. *<======Lots of commented out steps that need to be un-commented for next cycle============================. Rerunning 5-3-14 after some updates to newbgvars.sas . (But finding all the input sets gone!!) -- */ title "&pgm"; options compress=yes; %let vintage=2012; %let period=5yr; *<=====; libname acs2012 '/pub/data/acs2012'; *<=====; libname acs (acs&vintage); libname user '/SAS_temp/userb'; filename nomatch "&pgm..nomatch.txt"; *---here we write messages indicating geos not matched between acs and sf1---; *<=====The acs.usbgstemp data set was deleted between Feb and May. So we rerun these steps to recreate it (temporarily!) ----; /*<=========================Comment out===================================== data allxmoe; set acs.usmcdcprofiles5yr(drop=%varlist(*_moe,acs.usmcdcprofiles5yr) ); where sumlev='150'; run; data moeonly; set acs.usmcdcprofiles5yr(keep=sumlev %varlist(*_moe,acs.usmcdcprofiles5yr) ); where sumlev='150'; run; data acs.usbgstemp ; merge allxmoe moeonly; run; ===========================End commented out================================ */ *----We broke the original usmcdcprofiles5yr dataset into 3 pieces: usbgstemp, ustractstemp and the rest (usmcdcprofiles5yralt) .-----; data usbgsacsTemp(label='Temp blkgrp level data with limited variables' compress=no); retain vintage "&vintage" period "&period"; *<===========================; length esriid $12 county $5 tract $7 bg $1; *<====note: we renamed puma5 to puma prior to running this step ===; set acs.usbgstemp( drop=areaname period years geocomp_name geocomp placefp geocomp_name UA--CongDist concit--BTBG FullTimeWorkers--pctPoorOver65 FullTimeWorkers_moe--poorOver65_moe Over16--pctEmployedFemales Over16_moe--EmployedFemales_moe Women15to50--pctGrandPrntsCaring5orMore Women15to50_moe--GrandPrntsCaring5orMore_moe TotPopNonInst--pctDisabledElder TotPopNonInst_moe--DisabledElder_moe Over1--pctSpanishEnglishLTD Over1_moe--SpanishEnglishLTD_moe ); *** where sumlev='150'; *--already a subset--; **esriid=substr(geoid,8); county=substr(geoid,8,5); tract=substr(geoid,13,4)||'.'||substr(geoid,17,2); BG=substr(geoid,19,1); **period='5yr'; drop geoid; label sumlev=' '; run; *---we have 51 state-level sf1x datasets. Here we concatentate and shrink (selects vars) those sets.--; %macro setref(state,stab); sf12010x.&stab.bgs150(keep=esriid areaname state stab county tract bg intptlat intptlon LandSQMI AreaSQMI totpop totpop00 tothhs GQpop rename=(totpop=totpopsf1 GQpop=Gqpopsf1 tothhs=TotHHssf1)) %mend setref; data sf1xusbgs(compress=no); set %dostates(n=51,mac=setref) open=defer; run; data _null_; file nomtch; put; run; *---clear out file for do-over runs---; *******The plan is to rename this without the "2" once we know the setup is working***************************; data usbgs5yrtemp2( label="National 5-yr Summaries for BGs with SF1 data" ); update sf1xusbgs(in=insf1) usbgsacstemp(in=inacs where=(state ne '72')) end=_lastobs; by esriid; *drop geocode; retain _nomatch 0; retain cbsayr '2012'; *--Even though it comes from sf1 it is still current as of 12/12 ---; label totpopsf1='2010 Census Total Pop count' tothhssf1='Total HHs 2010 Census count'; if not (inacs and insf1) then do; file nomatch mod; if _nomatch=0 then put / "Unmatched tempusbgs observations. As run at &sysdate &systime"; _nomatch+1; if _n_ gt 100 and _n_ - _nomatch < 20 then do; file log; put "***Too many non matches. Step aborting ****"; stop; end; if inacs then _msg="Not in SF1"; else _msg="Not in ACS"; put _msg +1 esriid= county= $county.; if not inacs then delete; end; if _lastobs and _nomatch then do; file log; put '**** ' _nomatch ' observations not matched between acs and sf1 '; end; drop _: ; label sumlev=' '; run; *----------------This update step gets us a few more variables that before were all missing-------------------*; data acs.usbgs5yr( index=(state) label="National BG data with SF1 data merged" ); update usbgs5yrtemp2 (in=inmaster) acs.newbgvars5yr(keep=esriid state logrecnoC _numeric_ where=(state ne '72') in=innewvars) end=_lastobs; by esriid; if inmaster; if innewvars then do; array nums(*) ManProfOccs ServiceOccs SalesOffOccs FarmFishOccs ConsOccs TransOccs Agriculture Construction Manufacturing WholesaleTrade RetailTrade Transportation Information Finance_ins Professional Educ_health_SocSvcs RecreationEtc OtherIndustries PublicAdmin PrivWageWorkers GovWorkers SelfEmpWorkers UnpaidFamWorkers Civilian ArmedForces; array pcts(*) PctManProfOccs PctServiceOccs PctSalesOffOccs PctFarmFishOccs PctConsOccs PctTransOccs PctAgriculture PctConstruction PctManufacturing PctWholesaleTrade PctRetailTrade PctTransportation PctInformation PctFinance_ins PctProfessional PctEduc_health_SocSvcs PctRecreationEtc PctOtherIndustries PctPublicAdmin PctPrivWageWorkers PctGovWorkers PctSelfEmpWorkers PctUnpaidFamWorkers PctCivilian PctArmedForces; if EmployedCLF then do _i=1 to dim(pcts); pcts{_i}=nums{_i}*100/EmployedCLF; end; end; format landsqmi 9.2; drop metrodiv; drop _i; run; data two; set acs.usbgs5yr(obs=2); run; proc fsbrowse printall data=two; title2 'acs.usbgs5yr'; run;