x cd /pub/data/acs2010/Tools; %let pgm=mcdcprofiles5yr; filename pgm "&pgm..sas"; *---Process the full 5-year period estimates file as created by bcs from downloaded base tables. Here we create multiple data sets based on geography. The partitioning is modeled after the way we procssed 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: As of 3-5-12 we have successfully created most of the datasets. 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. ---*; %let year=2010; %let yr=%substr(&year,3,2); %let yearm4=%eval(&year -4); %let yrm4=%substr(&yearm4,3,2); libname acs "/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--; data acs.usmcdcprofiles5yr(label='Std profile data for all geos in US using 2006-2010 data'); length stab $2; set acs.usmcdcprofiles5yr_old; if state ne ' ' then stab=upcase(put(state,$fipstab2.)); ****************************4-4-12: Fix of problem with old usmcdcprofiles5yr data set which we have manually renamed today. The AvgHValue variable was using the wrong denominator.**; if OwnerOcc then do; AvgHValue=(OccHUs/OwnerOcc)*AvgHValue; AvgHValue_moe=.; *<---We need the moe of the aggregate value of owner units. Need to go back to base tabs-; end; 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; ==========================end comment====================================== */ /* ========================begin comment==================================== %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) usstcnty(label="National 5-yr State and County Summaries" &dgc) uscousubs(label="National 5-yr County Subdivision/MCD Summaries" &dgc) usplaces(label="Place (city &dgc) and place/county summaries" &dgc) uscdslds(label="National 5-yr CD11 and 2008 State Leg District summaries" &dgc) acs.usamindianetc5yr(label="National 5-yr Indian Reservation etc summaries" &dgc) usmetros(label="National 5-yr summaries for MSAs (CBSAs), CSAs, Metro Divs, NECTAs etc" &dgc) ustracts(label="National 5-yr summaries for Census tracts" &dgc) acs.uspumas5yr (label="National 5-yr summaries for 2000 PUMAs" &dgc) usschools(label="National 5-yr summaries for School Districts" &dgc) acs.usurbareas5yr(label="National 5-yr summaries for urban areas as defined in 2002" &dgc) ; ***acs.uszips(label="National ZCTA (complete and within state/county) summaries" drop=&phctrvars &pcovars compress=binary index=(zcta5)); length SumLev $3 esriid $12; set acs.usmcdcprofiles5yr2; by geoid; *---forces the sort order----; retain _first 1; format geoid areaname geocomp_name ; label geoid=' ' areaname=' ' state=' ' geocomp=' ' county=' ' puma=' ' cbsa=' ' placefp=' ' metdiv='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 &yearm4.-&year but we find: " period= years= / '***Conversion will abort***'; abort abend; end; _first=0; end; *** format IntPtLon 11.6 IntPtLat 10.6; *<--added 7-13-01-; 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; 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 usstcnty; else if sumlev='060' then output uscousubs; else if sumlev='140' then output ustracts; else if sumlev in('160','155') then output usplaces; else if sumlev in ('500','510','610','612','620','622') then output uscdslds; else if ('250' <= sumlev <= '299') or sumlev='230' then output acs.usamindianEtc5yr; else if ('310' <= sumlev <= '370') then output usmetros; else if sumlev in ('950','960','970') then output usschools; else if sumlev='795' then output acs.uspumas5yr; else if sumlev='400' then output acs.usurbareas5yr; else put '**** sumlev not expected: ' sumlev=; drop _: ; run; ==========================end comment====================================== */ ods html file="../&pgm..html"; %let totpop00=totpop00; data _null_; file nomtch; put; run; *<============clear out nomatch file so we can write to it mod----; ods listing close; *------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,dropvars=,index=1,sort=0,byvars=esriid,geos=); %if &sort %then %do; proc sort data=&setname force; by &byvars; run; %end; data acs.&setname.5yr ( %if &index %then %str ( index=(state)) label="National 5-yr Summaries for &geos with SF1 data" ); ; update sf1x.&setname (keep=_character_ intptlat intptlon LandSQMI AreaSQMI totpop &totpop00 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 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 _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 sumlev= esriid= areaname= ; 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 _: &dropvars; ** tract cousubfp placefp ua zcta5 puma; run; %mend mergem; options mprint; /* ========================begin comment==================================== %mergem(usstcnty,dropvars=tract cousubfp placefp ua zcta5 puma,sort=1,geos=States and Counties) ; %mergem(uscousubs,dropvars=tract placefp ua zcta5 puma,geos=County Subdivisions) ; %mergem(ustracts,dropvars=cousubfp placefp ua zcta5 puma,geos=Census Tracts) ; %mergem(usschools,dropvars=cousubfp placefp tract ua zcta5 puma,sort=1,byvars=state sumlev esriid,index=1,geos=School Districts) ; data uscdslds; set uscdslds; where sumlev in ('500','610','620'); *--all we have on the sf1 set--; %mergem(uscdslds,dropvars=cousubfp placefp tract ua zcta5 puma,sort=1,byvars=state sumlev esriid, index=1,geos=%str(Cong Dists 511 & 2009 SLDs) ) ; %mergem(usplaces,dropvars=cousubfp tract ua zcta5 puma,sort=1,byvars=esriid) ; ==========================end comment====================================== */ %let totpop00=; ***proc datasets library=sf1x nolist ;*** modify usmetros; *** index create sumesr=(sumlev esriid); *** quit; %mergem(usmetros,dropvars=,sort=1,geos=Metro Areas,byvars=sumlev esriid); %contdir(acs); run; ods html close; *<---local utility for OSEDA use only. Others can delete this line---;