x cd /pub/data/acs2011/Tools; %let pgm=mcdcprofiles5yr; filename pgm "&pgm..sas"; *---Rerunning 3-8-13 after finding problem with state code assigned to zctas (860 sumlevs)-----*; *---Process the full 5-year period estimates file as created by gr from downloaded base tables. Here we create multiple data sets based on geography. The partitioning is modeled after the way we processed the sf1 national file for 2010. In fact, we attempt to match obs on the parallel data sets and transfer the 2010 census total pop figure and some GIS vars (lat-long coords, areas) as part of the output acs data sets. John Blodgett, OSEDA, under contract with the Missouri Census Data Center. November, 2011. Note that we do not have sf1 data for metros or for county portions of places and cdslds. In the latter case we went ahead and did the merge but the sf1-based variables are missing for the within-county summaries. Rerunning 1-8-13 after job tempusbgs.sas run to create 3 new "temp" input sets, with tracts and bgs separated from the rest of usmcdcprofiles5yr. In the future we hope to get those data sets directly from GR. **************NOTE! *************************************************** We shall do the bgs datasets in a separate run, usbgprofiles.sas . **************NOTE! *************************************************** ---*; %let year=2011; %let yr=%substr(&year,3,2); %let yearm4=%eval(&year -4); %let yrm4=%substr(&yearm4,3,2); libname acs "/pub/data/acs&year"; libname acs&year "/pub/data/acs&year"; libname sf1x '/pub/data/sf12010x'; filename nomatch "&pgm..nomatch.txt"; *---here we write messages indicating geos not matched between acs and sf1---; libname user '/SAS_temp/user'; options compress=binary; /* ========================begin comment==================================== *---Add the stab variable to the usmcdcprofiles5yr data set--; *---Here was also add a "primary" State code to the 860-level (complete ZCTAs). There was a problem with this code on orginal run back in January so we have to rerun in March, 2013. ----; data acs.usmcdcprofiles5yr(label='Std profile data for all geos in US using 2006-2010 data'); length stab $2; set acs.usmcdcprofiles5yr_old; if sumlev='860' then do; length zcta5 $5; zcta5=substr(geoid,8,5); *--Assign the "primary" state, i.e. the one the ZIP shares the most pop with---; state=zipfips(zcta5); *if length(state)=1 then state='0'||substr(state,1,1); if substr(state,1,1)=' ' then substr(state,1,1)='0'; end; if state ne ' ' then stab=upcase(put(state,$fipstab2.)); run; proc datasets library=acs nolist; modify usmcdcprofiles5yr; index create state; index create sumlev; index create county; quit; *----lets begin by regenerating the input dataset so that all the _moe variables are at the end----; data allxmoe; set acs.usmcdcprofiles5yr(drop=%varlist(*_moe,acs.usmcdcprofiles5yr) ); run; data moeonly; set acs.usmcdcprofiles5yr(keep=%varlist(*_moe,acs.usmcdcprofiles5yr) ); run; data acs.usmcdcprofiles5yr2; merge allxmoe moeonly; run; proc datasets library=acs nolist; modify usmcdcprofiles5yr2; index create geoid; index create state; index create county; quit; *---We saved the log from running the above code in &pgm._1strun.log -----; ==========================end comment====================================== */ *---Begin Part II: Breaking data down into geography-based subsets----*; %let dgc=%str(drop=geocomp geocomp_name); /* ========================begin comment==================================== data acs.usgeocomps5yr(label="5-yr Summaries for geographic components of various geographies") acs.usregdiv5yr(label="5-yr Summaries for the nation, Regions, and Divisions" compress=no &dgc) usstcnty5yr(label="National 5-yr State and County Summaries" &dgc) uscousubs5yr(label="National 5-yr County Subdivision/MCD Summaries" &dgc) usplaces5yr(label="Place (city &dgc) and place/county summaries" &dgc) uscdslds5yr(label="National 5-yr CD11 and 2008 State Leg District summaries" &dgc) uszctas5yr(label="National 5-yr ZIP Census Tab Area summaries" &dgc index=(state)) acs.usamindianetc5yr(label="National 5-yr Indian Reservation etc summaries" &dgc) usmetros5yr(label="National 5-yr summaries for MSAs (CBSAs), CSAs, Metro Divs, NECTAs etc" &dgc) acs.uspumas5yr (label="National 5-yr summaries for 2000 PUMAs" &dgc) usschools5yr(label="National 5-yr summaries for School Districts" &dgc) acs.usurbareas5yr(label="National 5-yr summaries for urban areas as defined in 2002" &dgc) ustractsH5yr(label="National 5-yr summaries for hierarchal tracts (level 080)" &dgc) ustracts5yr(label="National 5-yr summaries for complete Census tracts " &dgc) ; length SumLev $3 esriid $22 vintage $4 period $3; *---increased esriid length to handle 080 levels which are 21 long---; set acs.usmcdcprofiles5yr2; ***set acs.usmcdcprofiles5yrTEMP acs.ustractstemp; by geoid; *---forces the sort order----; retain _first 1; retain vintage "&year"; drop years; format geoid areaname geocomp_name ; label geoid=' ' areaname=' ' state=' ' geocomp=' ' county=' ' puma=' ' cbsa=' ' placefp=' ' metrodiv='Metro Div.' DateCreated=' '; if _first then do; if period='5yr' and years=:"&yearm4" then ; else do; file log; put "******Problem with input dataset. We need the 5yr data file for vintage &year but we find: " period= vintage= years= / '***Conversion will abort***'; abort abend; end; _first=0; end; *** format IntPtLon 11.6 IntPtLat 10.6; *<--added 7-13-01-; if sumlev='150' then delete; *<=====DO the block group data separately. See setup usbgprofiles.sas, at least for now. ; if sumlev in ('067','070','170','172','258','259','293','294','354','312','313','316','352','353','354','357','358','550') then delete; if sumlev in ('320','321','322','323','324','332','333','337','338','340','341','345','346','355','356', '360','361','362','363','364','365','366' ) then delete; *--redundant or unwanted metro levels---; if state='72' then delete; *---avoid PR and all its special cases----; esriid=substr(geoid,8); *----AS OF 3-3-12 there are lots of missing ID variables on the incoming usmcdcprofiles5yr dataset. While we plan to fix this we are not assuming that many of these variables are available here. Instead we plan to rely on the merging with the corresponding sf1x datasets and picking up the other key ID variables from those sets. We shall be matching on esriid. ----; *-----output the data sets. ---------------*; *---On first run we had usregdistates and counties. But decided to group states with counties for final run, now usregdivs and usstcnty; if geocomp gt '00' then output acs.usgeocomps5yr; else if sumlev le '030' then output acs.usregdiv5yr; else if sumlev='050' or sumlev='040' then output usstcnty5yr; else if sumlev='060' then output uscousubs5yr; else if sumlev ='080' then output ustractsH5yr; else if sumlev ='140' then output ustracts5yr; else if sumlev='860' then output uszctas5yr; else if sumlev in('160','155') then output usplaces5yr; else if sumlev in ('500','510','610','612','620','622') then output uscdslds5yr; else if ('250' <= sumlev <= '299') or sumlev='230' then output acs.usamindianEtc5yr; else if ('310' <= sumlev <= '370') then output usmetros5yr; else if sumlev in ('950','960','970') then output usschools5yr; else if sumlev='795' then output acs.uspumas5yr; else if sumlev='400' then output acs.usurbareas5yr; else put '**** sumlev not expected: ' sumlev=; drop _: ; run; *************Alternate step 2 where all we process this time is the zcta data ****************; %macro altstep2( ); data uszctas5yr(label="National 5-yr ZIP Census Tab Area summaries" &dgc index=(state)) ; length SumLev $3 esriid $5; ***set acs.usmcdcprofiles5yr2; set acs.usmcdcprofiles5yr2 ; **** acs.ustractstemp; where sumlev='860'; by geoid; *---forces the sort order----; retain _first 1; format geoid areaname geocomp_name ; label geoid=' ' areaname=' ' state=' ' geocomp=' ' county=' ' puma=' ' cbsa=' ' placefp=' ' metrodiv='Metro Div.' DateCreated=' '; if state='72' then delete; esriid=substr(geoid,8); drop _: ; run ; *---We are already creating the set in the big step, just above----; %mend altstep2; %*altstep2 ; ods html file="../&pgm..html"; data _null_; file nomatch; put; run cancel; *<============clear out nomatch file so we can write to it mod----; ods listing close; ==========================end comment====================================== */ %let totpop00=totpop00; *------Here we merge these ACS data sets with the corresponding 2010 sf1 extract sets where we hope to pick up the ID variables, lat-long coordinates and 2000 populations. -----------*; %macro mergem(setname,setname1x=,dropvars=,index=1,sort=0,byvars=esriid,geos=,morenumvars=); %if &sort %then %do; proc sort data=&setname force; by &byvars; run; %end; %if &setname1x=%str() %then %let setname1x=&setname; %let _lennamem2=%eval( %length(&setname1x) - 2); %let _lennamem3=%eval( %length(&setname1x) - 3); %if %substr(&setname1x,&_lennamem2,3)=%str(5yr) %then %let setname1x=%substr(&setname1x,1,&_lennamem3); %put ***setname=&setname setname1x=&setname1x _lennamem2=&_lennamem2 _lennamem3=&_lennamem3 ; data acs.&setname ( %if &index %then %str ( index=(state)); label="National 5-yr Summaries for &geos with SF1 data" ); ; update sf1x.&setname1x (keep=_character_ intptlat intptlon LandSQMI AreaSQMI totpop &totpop00 &morenumvars rename=(totpop=TotPopsf1) in=insf1) &setname (in=inacs where=(state ne '72')) end=_lastobs; by &byvars ; drop geocode; retain _nomatch 0; label totpopsf1='2010 Census Total Pop count'; if sumlev='155' then insf1=1; *--just to avoid the errors, since we know we do not have 155 levels on sf1.usplaces--; if sumlev='080' then insf1=1; *--same thing---; if not (inacs and insf1) then do; file nomatch mod; if _nomatch=0 then put / "Unmatched &setname observations. As run at &sysdate &systime"; _nomatch+1; if _n_ gt 100 and (5*_nomatch > _n_) 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 sumlev= esriid= areaname= TotPop= TotPopsf1= ; if not inacs then delete; *<---------------------------------; end; if _lastobs and _nomatch then do; file log; put '**** ' _nomatch ' observations not matched between acs and sf1 '; end; format landsqmi 9.2; drop _: &dropvars; ** tract cousubfp placefp ua zcta5 puma; label sumlev=' '; run; %mend mergem; options mprint; /* ========================begin comment==================================== %mergem(usstcnty5yr,dropvars=tract cousubfp placefp ua zcta5 puma,sort=1,geos=States and Counties) ; %mergem(uscousubs5yr,dropvars=tract placefp ua zcta5 puma,geos=County Subdivisions) ; %mergem(usschools5yr,dropvars=cousubfp placefp tract ua zcta5 puma,sort=1,byvars=state sumlev esriid,index=1,geos=School Districts) ; data uscdslds5yr; set uscdslds5yr; where sumlev in ('500','610','620'); *--all we have on the sf1 set--; %mergem(uscdslds5yr,dropvars=cousubfp placefp tract ua zcta5 puma,sort=1,byvars=state sumlev esriid, index=1,geos=%str(Cong Dists 511 & 2009 SLDs) ) ; %mergem(usplaces5yr,dropvars=cousubfp tract ua zcta5 puma,sort=1,byvars=sumlev esriid) ; %let totpop00=; ***proc datasets library=sf1x nolist ;*** modify usmetros; *** index create sumesr=(sumlev esriid); *** quit; %mergem(usmetros5yr,dropvars=,sort=1,geos=Metro Areas,byvars=sumlev esriid); %mergem(ustracts5yr,dropvars=cousubfp placefp ua zcta5 puma,geos=Census Tracts,byvars=sumlev esriid) ; %mergem(uszctas5yr,setname1x=uszips860,sort=0,byvars=zcta5,geos=ZCTAs,morenumvars=PctState PctCnty Naltzips); ==========================end comment====================================== */ %let totpop00=; %mergem(ustractsh5yr,setname1x=ustracts080,dropvars=zcta5 puma,geos=Hierarchal Census Tracts,byvars=esriid) ; /* ========================begin comment==================================== NO - not this way any more!! data acs.ustractsH5yr(label="National 5-yr summaries for hierarchal tracts (level 080)" &dgc) ; length SumLev $3 esriid $22 State $2 stab $2 county $5 tract $7 cousubfp placefp $5 AreaName $90; set ustractsH5yr; county=substr(esriid,1,5); cousubfp=substr(esriid,6,5); placefp=substr(esriid,11,5); tract=substr(esriid,16,4)||'.'||substr(esriid,20,2); *--our conventional format: xxxx.xx---*; run; ==========================end comment====================================== */ *------------------------------Create Missouri subset views of the us data sets----------------------------------*; proc sql; %macro cv(setname); create view acs2011.mo&setname.5yr as select * from acs2011.us&setname.5yr where state='29'; %mend cv; /* ========================begin comment==================================== %cv(cdslds) %cv(cousubs) %cv(places) %cv(pumas) %cv(schools) %cv(stcnty) %cv(stcnty) %cv(tracts) %cv(zctas) ==========================end comment====================================== */ %cv(tractsH) ; title "&pgm run for Vintage &year Run on &sysdate"; %contdir(acs); run; ods html close; *<---local utility for OSEDA use only. Others can delete this line---;