x cd /pub/data/acs2013/Tools; %let pgm=usbgprofiles; filename pgm "&pgm..sas"; /*--Generate acs.usbgs5yr J. Blodgett, OSEDA, Dec, 2014 . Input data set acs.usbgstemp was created by mcdcprofiles5yr.sas. The acs.newbgvars5yr was created by job newbgvars.sas . First attempt at running will NOT involve using a newbgvars update set. We shall try running it without that to see if updates appear necessary. -- */ title "&pgm"; options compress=yes; %let vintage=2013; %let period=5yr; *<=====; libname acs2013 '/pub/data/acs2013'; *<=====; 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---; /*<=========================Comment 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 TAZ concit--aianhh 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---; data usbgs5yrtemp( 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 '2013'; *--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; ===========================End commented out================================ */ data acs.usbgs5yr( index=(state) label="National BG data with SF1 data merged" ); set usbgs5yrtemp; run cancel; *<====for now we just copy it===============; *---12-16-14 we change strategies after deciding we did need the extra value of newbgvars. So we cancel the copy and uncomment next step; *----------------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 usbgs5yrtemp (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;