x cd /pub/data/bls_la/Tools; %let pgm=bls_la_cnvt; filename pgm "&pgm..sas"; *--- The LA local unemployment time series data from the BLS are periodically downloaded from their web site ftp://ftp.bls.gov/pub/time.series/la/ and get converted here to a format more consistent with our way of looking at data. We create a single observation per geographic area/year (rather than the way the data are on input with 1 line per data item per month or annual avg, which is rather cumbersome). Initial coding, jgb, OSEDA - Feb. 2007 . Running with newly download data, Dec. 2007 Running with newly downloaded data, July, 2008 Running with newly downloaded data, March 2009 (data thru 12/08 with 12/08 prelim) Running with newly downloaded data, June 2013 (data from 1990 thru April 2013) ---*; libname user '/SAS_temp/user'; libname bls '/pub/data/bls_la'; %*let asof=Jul2008; %*let asof=Mar2009; %let indir=rawdata_june13; %let asof=Jun2013; %let datathru=April 2013; *<---used in dataset label---------; %let yr=%substr(&asof,6,2); *<====; filename areacds "/pub/data/bls_la/&indir./la.area"; filename xwalk '/pub/data/bls_la/cntyfipsaug2004.csv'; libname georef '/pub/data/georef' access=readonly; title "&pgm : Convert bls_la data as of &asof for US"; options NOmprint; %let filter= %str( ); *<-------complete processing run-----; /* =======================Begin comment================ *---Read the BLS areacodes to FIPS code crosswalk file sent by BLS (James Campbell, 2-21-07). We'll need this to attach FIPS codes to county level data.---; *---We did NOT rerun this step when processing the 2013 data---; data bls.areacd2fips(label='BLS County Area Codes to FIPS, 2004' index=(areacode8)); infile xwalk dsd firstobs=2; length areacode8 $8 State $2 cntyname $64 _cnty $3 ; input areacode8 -- _cnty; length fipco $5 AreaType $2 AreaCode $6; AreaType=substr(areacode8,1,2); Areacode=substr(AreaCode8,3,6); fipco=State||_cnty; if put(fipco,$county.) = fipco then do; _nbad+1; if _nbad ge 20 then abort abend; put fipco= ' *** not found in $county format *** ' _all_; end; drop _: ; run; ======================End comment================== */ data bls.areacodes&yr(label='BLS Area Codes used in these data' ); infile areacds dsd dlm='09'x missover firstobs=2; length AreaType1 $1 AreaCode $6 _AreaCode $8 AreaName $80 Display_level $2 Selectable $1 Sort_Sequence 5; length AreaType $2; length State $2 County $5 Reg Div $1 mcode mtype $5 PlaceFP $5 MetroDiv CSA $5; label mcode='CBSA/NECTA code' mtype='Metro Area Type' CSA='Combined Stat Area'; input AreaType1 _Areacode -- Sort_Sequence; *if _n_ le 5 then put / _all_; AreaType=substr(_areacode,1,2); Areacode=substr(_areacode,3,6); *--these vars come from keyed read when 050 sumlev detected. We need to make sure they get reset to blanks--; State=' '; County=' '; fipco=' '; length cntyname $64; cntyname=' '; select (areatype1); when ('A') SumLev='040'; when ('B','D') SumLev='310'; when ('C') SumLev='314'; when ('E') SumLev='330'; when ('F') SumLev='050'; when ('G','H') sumlev='160'; when ('I') SumLev='155'; when ('M') Sumlev='020'; when ('N') SumLev='030'; when ('J','K','L') SumLev=' '; end; *---here we try to extract specific component codes to facilitate linking with other datasets--; select (sumlev); when ('020') Reg=substr(_areacode,4,1); when ('030') Div=substr(_areacode,4,1); when ('040') do; State=substr(_areacode,3,2); if State='43' then State='72'; *--they use the old 43 for Puerto Rico--; end; when ('050') do; State=substr(_areacode,3,2); if State ne '02' then do; areacode8=_areacode; set bls.areacd2fips(keep=Areacode8 State fipco cntyname areacode rename=(areacode=_areacodeck) ) key=areacode8; drop areacode8; if areacode ne _areacodeck then do; put '**Problem with areacode check ***' / _all_; _nbad+1; if _nbad gt 20 then abort abend; end; end; else do; *--Alaska processing--; *State=substr(_areacode,3,2); fipco=substr(_areacode,3,5); cntyname=put(county,$county.); areacode=_areacode; end; County=fipco; end; when('155') do; State=substr(_areacode,3,2); County='xxxxx'; PlaceFP='xxxxx'; *--the x s indicate the code is relevant but unknown--; end; when('160') do; State=substr(_areacode,3,2); PlaceFP='xxxxx'; end; when('310') do; mcode=substr(_areacode,5,4)||'0'; *--This is the CBSA or NECTA code. They dropped the ending 0 --; if index(areaname,'Metropolitan') then mtype='metro'; else if index(areaname,'Micropolitan') then mtype='micro'; else if index(areaname,'NECTA') then mtype='necta'; State=substr(_areacode,3,2); end; when('314') do; State=substr(_areacode,3,2); MetroDiv=substr(_areacode,5,3); *--It can also be a necta div---; end; when ('330') do; State=substr(_areacode,3,2); CSA=substr(_areacode,5,3); *--It can also be a combined necta area---; end; when(' ') ; end; drop _: ; run; proc sort data=bls.areacodes&yr; by areatype areacode areatype1; run; title2 "bls.areacodes"; proc freq data=bls.areacodes&yr; Table AreaType1*AreaType*SumLev/list missing; Table State mtype metrodiv csa /missing; run; proc print data=bls.areacodes&yr(obs=50); run; *----Following 2 steps are probably not relevant except they provide some insight as to the problems we had to overcome--; data bls.areadups&yr; *---we create a dataset that ids codes that are reused as both place and county types--; set bls.areacodes&yr; by areatype areacode; if not (first.areacode and last.areacode); *--we should have 102 obs here, 51 dup pairs--; if first.areacode and areatype1 ne 'F' then do; put /'***Logic area processing bls.areadups. First obs of dup pair is not an F record ***' /_all_; abort abend; end; if last.areacode; *--the first of the dups always has 'F' as type code. We keep the G or H code--; keep areatype areacode areatype1 ; run cancel; *proc print data=bls.areadups; *proc datasets nolist library=bls; * modify areadups; * index create typecode=(areatype areacode); * quit; data la_raw; *--yes, it is a pun--; infile "/pub/data/bls_la/&indir/la.data.*" dsd dlm='09'x missover; *<====downloaded circa 6/25/2013 9:37:01 AM.; **infile "/pub/data/bls_la/&indir/la.data.14.Delaware" dsd dlm='09'x missover; *<---test file---; length _seriesid $17 _period $3 Year $4 ; input _seriesid @; if _seriesid='series_id' then delete; *<---ignore header lines---; input Year _period _datum ; if substr(_seriesid,1,2) ne 'LA' then do; put / '****Problem with data file - line found that is not a header and does note have "LA" in cols 1-2 ..aborting****'; abort abend; end; length Seasonal $1 _AreaCode $8 _measure $2; Seasonal=substr(_seriesid,3,1); _AreaCode=substr(_seriesid,4,8); _measure=substr(_seriesid,12,2); drop _seriesid; run; proc sort data=la_raw; by year seasonal _AreaCode _period _measure; run; data la52; *<---where we collapse the data into a 13 x data array (13 periods for 4 measures) with 1 obs per year and areacode (geographic area)--------; set la_raw; retain; by year seasonal _AreaCode _period _measure; length AreaType $2 AreaCode $6 default=5; array d(4,13) uerateM1-uerateM12 uerateAvg unempM1-unempM12 unempAvg empM1-empM12 empAvg clfM1-clfM12 clfAvg; format uerate: 5.1; if first._areacode then do; Areatype=substr(_Areacode,1,2); AreaCode=substr(_areacode,3,6); do _m_=1 to 4; do _p_=1 to 13; d(_m_,_p_)=.; end; end; end; *---conversion from character to numeric will take place in next 2 statements--; _p_=substr(_period,2,2); _m_=_measure - 2; d(_m_,_p_)=_datum; drop _: ; if last._areacode then output; run; proc sort; by areatype areacode; run; data usstcnty (label='State and County Level unemployment data by year'); merge bls.areacodes&yr(in=ingeos where=(sumlev in ('040','050'))) la52(in=indata); by areatype areacode; if ingeos and indata; run; proc sort data=usstcnty; by state county ; run; data bls.usstcnty&yr (label="State and County Level unemployment data by year 1990 thru &datathru"); length SumLev $4 Year $4 State $2 County $5 Seasonal $1; merge usstcnty (in=in1) georef.cbsacos(in=in2 keep=state county cbsa cbsaname cbsatype year rename=(year=cbsayr)) end=last; by state county; if not (in1 and in2) and sumlev='050' and last.county then do; _nbad+1; if _nbad le 100 then put / _all_; else abort abend; end; *--Look up the us Region and Divisions codes when state is identified---; Length _rd $2; _rd=put(state,$stdivr2.); Reg=substr(_rd,1,1); Div=substr(_rd,2,1); if sumlev=' ' then delete; drop _: ; *------------------Calculate the annual avg if we have 12 mos of data and they did not provide it---; if unempAvg=. and unempm12 > 0 then unempavg=round( sum(of unempM:)/N(of unempM:) ); if empAvg=. and empm12 > 0 then empavg=round( sum(of empM:)/N(of empM:) ); if clfAvg=. and clfm12 > 0 then clfavg=round( sum(of clfM:)/N(of clfM:) ); if uerateAvg=. and unempm12 > 0 then uerateAvg=100*sum(of unempM:)/sum(of clfM:); drop mcode mtype placefp cntyname ; run; proc freq data=bls.usstcnty&yr; format state $state.; table state*reg*div /missing list; table state*sumlev/missing list; table sumlev*year/missing list; run; proc print data=bls.usstcnty&yr(obs=100); title2 "bls.usstcnty&yr"; run; proc sql; create view bls.mostcnty&yr as select * from usstcnty&yr where state='29'; quit; proc print data=bls.mostcnty&yr(keep=_character_ uerateAvg unempAvg empAvg clfAvg ); title2 "Selected Variables from bls.mostcnty&yr (View subset)"; by state ; id areacode year; where year ge '2012'; run; /* ========================begin comment==================================== ==========================end comment====================================== */