x cd /pub/data/acs2010/Tools; %let pgm=cnvt_workflows; filename pgm "&pgm..sas"; *---Convert (some) of the special workflow table data published by the Bureau at http://www.census.gov/hhes/commuting/ . These numbers are based on ACS data for the 5-year period and come with the usual MOE values. No details regarding the characteristics of the commuters, just counts by resident/workplace combos. Data are stored in the workflows subdirectory of this (acs2010) directory. Related directory: /pub/data/workflow : contains comparable data based on the 2000 decennial census. jgb, 11-11-13. ---*; %let vintage=2010; %let inpath=%str(/pub/data/acs&vintage/workflow); filename res_in "&inpath./Table1.csv"; libname workflow "/pub/data/acs&vintage./workflow"; libname georef '/pub/data/georef' access=readonly; *----Conversion step---; data usbyres (label='US county-level work flows sorted by Residence county' ); *---termstr here is very unusual. Apparently Kim downloaded the data in Mac format! ---; infile res_in firstobs=6 dsd termstr=cr lrecl=512 length=_l; length _cntyr _cntyw $3; length StateR $2 CountyR $5 cbsaR MetroDivR $5 AreanameR $40; length _statew3 $3 StateW $2 CountyW $5 cbsaW MetroDivW $5 AreanameW $40; *length CountryW $3; length Count 5 MOE 4; label stater='State of Residence' countyr='County of Residence' cbsaR='Metro/Micro-politan Stat Area of Residence' MetroDivR="Metro Division of Residence" AreanameR='Work Flows From (Residence)'; label statew='State of Work' countyw='County of Work ' cbsaW='Metro/Micro-politan Stat Area of Work' AreanameW='Work Flows Into...'; length StCountryW $40 _skipname $40; label StCountryW='Name of work State/Isl Area/Country'; **label countryW='Country of Work'; label count='Work Flows'; input stater _cntyr _statew3 _cntyw count moe _skipname _skipname StCountryW; if stater=' ' and _n_ gt 130000 then stop; *---there are some metadata lines at end of file---; if _l > 255 then do; _nlong+1; if _nlong le 50 then do; list; put _all_; end; else stop; end; CountyR=stater||_cntyr; if _statew3 <'056' or _statew3='072' then do; Statew=substr(_statew3,2,2); CountyW=Statew||_cntyw; end; else do; CountryW=_statew3; StateW='99'; CountyW='99999'; end; *---do keyed reads of georef.cbsacos to get the cbsa and metrodiv (and year) values. We get both R and W values-; county=countyr; drop county; if countyr ne lag(countyr) and stater ne '72' then do; cbsaR=' '; metrodivR=' '; AreanameR=' '; set georef.cbsacos(keep=cbsa metrodiv year county) key=county; cbsaR=cbsa; metrodivR=metrodiv; CBSAYr=year; AreanameR=put(countyR,$county.); end; retain cbsaR metrodivR cbsaYr AreanameR; county=countyw; if countyR=countyw then do; cbsaW=cbsaR; MetroDivW=MetroDivR; end; else if countyw ne '99999' and statew ne '72' then do; set georef.cbsacos(keep=cbsa metrodiv year county) key=county; cbsaW=cbsa; metrodivW=metrodiv; end; if _iorc_=1230015 then _error_=0; *--this is probably OK. --; if countyw ne '99999' then AreanameW=put(countyw,$county.); else AreanameW=stCountryW; drop _: county cbsa metrodiv year stCountryW; run; *---this sort leaves it sorted by residence county but then within that orders the data according to the # work flows--; proc sort out=workflow.usbyres(index=(stater)); by stater countyr descending count; run; *---define some indices for faster access---; proc datasets library=workflow; modify usbyres; *index delete statew; index create statew; *index delete countyr; index create countyr; *index delete countyw; index create countyw; quit; /*<=========================Comment out===================================== proc sql; create view workflow.usbywrk as select * from usbyres order by statew, countyw, count desc; quit; ===========================End commented out================================ */