x cd /pub/data/acs2013/Tools; %let pgm=mcdcprofiles5yr; filename pgm "&pgm..sas"; *---Running after process_mcdcprofiles5yr.sas which does the basic convert to create the acs.usmcdcprofiles5yr data set. 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. Rev. 12-6-14. to run with the vintage 2013 data. 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. **************NOTE! *************************************************** We shall do the bgs datasets in a separate run, usbgprofiles.sas . **************NOTE! *************************************************** ---*; %let year=2013; %let yr=%substr(&year,3,2); %let yearm4=%eval(&year -4); %let yrm4=%substr(&yearm4,3,2); %let fixpuma5=0; %*---if variable puma got named puma5 instead we "fix" it with a rename per this global parm--; 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; /*<=========================Comment out===================================== *----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.usmcdcprofiles5yralt(label='All sumlevs exc tract and bg, _moe vars last' drop=tract bg index=(sumlev)) acs.ustractstemp acs.usbgstemp; ; merge allxmoe moeonly; if sumlev='140' then output acs.ustractstemp; else if sumlev='150' then output acs.usbgstemp; else output acs.usmcdcprofiles5yralt; %macro fixit; %if &fixpuma5 %then %do; rename puma5=puma; %end; %mend fixit; %fixit ; run; proc datasets library=acs nolist; modify usmcdcprofiles5yralt; index create state; quit; *---Begin Part II: Breaking data down into geography-based subsets----*; %let dgc=%str(drop=geocomp geocomp_name); 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 CD113 and 2013 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) acs.usmetros5yr(label="National 5-yr summaries for MSAs (CBSAs), CSAs, Metro Divs, etc, 2013 defs" &dgc) acs.uspumas5yr (label="National 5-yr summaries for 2010 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.usmcdcprofiles5yralt acs.ustractstemp; by geoid; *---forces the sort order----; retain _first 1; retain vintage "&year"; drop years; format geoid areaname; format geocomp_name $geocomp40. ; label geoid=' ' areaname=' ' state=' ' geocomp=' ' county=' ' puma=' ' cbsa=' ' placefp=' ' metdiv='Metro Div.' DateCreated=' '; if period='5' then period='5yr'; if _first then do; ***Value of years was 2013 on input set for 2013. So we let it go by adding or condition.***; if period='5yr' and (years=:"&yearm4" or years="&year") 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','610','620') then output uscdslds5yr; else if ('250' <= sumlev <= '299') or sumlev='230' then output acs.usamindianEtc5yr; else if ('310' <= sumlev <= '370') then output acs.usmetros5yr; else if sumlev in ('950','960','970') then output usschools5yr; else if sumlev='795' then output acs.uspumas5yr; else if sumlev in ('400','410','430') 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.usmcdcprofiles5yralt; 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 ; *<============clear out nomatch file so we can write to it mod----; ods listing close; ===========================End commented out================================ */ %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; /*<=========================Comment out===================================== %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) ; ===========================End commented out================================ */ data sf1x.uscdslds2013temp; set sf1x.uscdsldspumas2012; where sumlev in ('500','610','620');run; *--all we have on the acs set--; %mergem(uscdslds5yr,dropvars=cousubfp placefp puma12 ua zcta5 puma,sort=1,byvars=state sumlev esriid, setname1x=uscdslds2013temp,index=1,geos=%str(113th CDs and 2013 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); *-----The Bureau is no longer (w vintge 2013) releasing data for the 080 (split tract) level----; %let totpop00=; %**mergem(ustractsh5yr,setname1x=ustracts080,dropvars=zcta5 puma,geos=Hierarchal Census Tracts,byvars=esriid) ; *------------------------------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; %cv(cdslds) %cv(cousubs) %cv(places) %cv(pumas) %cv(schools) %cv(stcnty) %cv(stcnty) %cv(tracts) %cv(zctas) %**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---;