x cd /pub/data/acspums/Tools; %let pgm=workforce_tables; filename pgm "&pgm..sas" ; /*---the request from Bill Edler 11-14-06. Wanted breakouts by US and Mo, ny cbsa-type (metro/micro/neither) for: % persons 25+ with bachelors degree %clf employed in management %clf employed in prof services %married couples who are both in the labor force. % of children 0-6 living in a family where both parents are in clf. % persons living in a different state 1 year ago. Median earnings (of people who actually had earnings). Mean travel time to work. % persons 65+ in clf. Note: the pums file does not have a field to ID the type of CBSA, if any. So we shall have to build an equivalency file that relates pumas to such areas. We created a CSV file using Geocorr to relate puma5 codes to cbsatype. We have two steps within this setup that just deal with creating equivalency files as SAS datasets. The puma2cbsatype dataset is created in the acspums data directory and this is what we use to create "adjusted weights" for our data based upon applying the allocation factors. (Geocorr is at https://mcdc.missouri.edu/applications/geocorr2000.html) . jgb, 11/2006. ---- */ title "2005 ACSPUMS Extraction Run: &pgm"; libname user '/SAS_temp/user'; options fmtsearch=(library, acspums); *---it should find the value labels format $occp in acspums.formats---; libname corrlst '/pub/data/corrlst'; filename csvin '/pub/data/corrlst/puma2cbsatype.csv'; libname acspums '/pub/data/acspums' ; /* =======================Begin comment (steps that already ran) ================ data corrlst.puma2cbsatype(label='US 2000 5% PUMA codes to CBSA Type (mero, micro, neither)' index=(state)); infile csvin firstobs=3 dsd missover; length State $2 PUMA5 $5 CBSAtype $5 Stab $2 pop2k 5 afact 8; input State -- afact; format afact 5.3; run; proc print data=corrlst.puma2cbsatype(obs=100); by state stab; id puma5; title2 "&syslast"; run; *--collape the correlation list so we have only 1 obs per puma with the 3 allocation factors for metro, micro and other-; data acspums.puma2cbsatype; set corrlst.puma2cbsatype(rename=(puma5=puma)); by state puma; if first.puma then do; PctMetro=0; PctMicro=0; PctOther=0; retain Pct: ; end; if cbsatype='Metro' then PctMetro=afact; else if cbsatype='Micro' then PctMicro=afact; else if cbsatype=' ' then PctOther=afact; if last.puma then output; *--just 1 obs per puma--; drop cbsatype afact pop2k; format Pct: percent6.1; label PctMetro='% of 2000 Pop in PUMA that is withn a Metropolitan Stat Area' PctMicro='% of 2000 Pop in PUMA that is withn a Micropolitan Stat Area' PctOther='% of 2000 Pop in PUMA outside any metro or micropolitan Stat Area' ; run; ======================End comment================== */ *----------------------------Here is the essence of the PUMS portion of this program, where we actually access the acspums data for the entire U.S.------------------------------------------; data &pgm.us; merge acspums.ushrecs05 acspums.usprecs05(in=inp); by st serialno; if inp; *--no vacant units--; keep st serialno puma agep pwgtp schl esr indp wkexrel sfn sfr mig migsp occp indp wkexrel jwmnp ; TotPop=1; keep totpop; length Over25 Bachelors InCLF InProfSvcs InManagement MarriedCoupleBothWork ChildUnder6 ChildUnder6BothParentsWork Earnings MovedFromDifferentState TravelTimeToWork Over65 Over65InLaborForce 5; keep Over25 -- Over65InLaborForce; Over25 = (agep ge 25); if Over25 then Bachelors= (schl ge '13'); InCLF = ('1' le esr le '3'); *--includes unemployed but in clf--; *--We have a problem with our $occp format code that we shall fix later. But for now we need to remove leading zeroes to make it do the lookup properly--; length _occp 8 _occp4 $4; _occp=occp; _occp4=left(put(_occp,4.)); if InCLF then InManagement= (put(_occp4,$occp3.) =: 'MGR'); if InCLF and _N_ le 100 then put '*** ' occp= _occp4= _occp4 $occp.; if InCLF then InProfSvcs= ('7270' le indp le '7690'); Over65 = (agep ge 65); if Over65 then Over65inLaborForce= InClf; if first.serialno then do; *--need data a HH level regarding householder and spouse married and both in CFL---; _headworks=InCLF; retain _headworks; _BothInCLF=0; retain _BothInCLF; end; else if rel='01' then do; *--we have a spouse, so we have a married couple familary hh--; MarriedCouple=1; _BothInCLF= ( _headworks and InCLF); MarriedCoupleBothWork= _bothinclf; *--this is only defined for this single output obs and gets weighted per the spouse weight, which ought to be as good as any--; end; if pernp gt 0 then Earnings=pernp; TravelTimeToWork=jwmnp; ChildUnder6= (agep le 6); if ChildUnder6 then ChildUnder6BothParentsWork=_bothinclf; if agep > 0 then MovedFromDifferentState=( migsp ne ' ' and (st ne substr(migsp,2,2))); rename st=State; *<==============Note===========; run; proc sort; by state puma; run; data &pgm.us2(label='With cbsatype and adjwt added'); merge &pgm.us(in=inpums) acspums.puma2cbsatype(in=inclist); by state puma; if inpums; if PctMetro then do; cbsatype='Metro '; adjwt=pwgtp*pctmetro; link output; end; if PctMicro then do; cbsatype='Micro '; adjwt=pwgtp*pctmicro; link output; end; if PctOther then do; cbsatype='Other'; adjwt=pwgtp*pctother; link output; end; return; output: *--this little output routine writes observations in Missouri twice, once tagged as state 00 (US totals) and once as 29-; if state='29' then output; _savestate=state; state='00'; output; *---for us totals---; state=_savestate; *---needed to avoid problems with merge logic----; return; drop _: ; run; proc sort data=&pgm.us2; by state; run; ods html file="&pgm..html" style=sasweb; title2 'Tables for Missouri and United States'; proc tabulate data=&pgm.us2; by state; format state $state.; freq adjwt; class cbsatype ; var TotPop Over25 Bachelors InCLF InProfSvcs InManagement MarriedCoupleBothWork ChildUnder6 ChildUnder6BothParentsWork Earnings MovedFromDifferentState TravelTimeToWork Over65 Over65InLaborForce ; table (bachelors inclf inprofsvcs inmanagement MarriedCoupleBothWork childunder6bothparentswork Movedfromdifferentstate over65inlaborforce) * (sum='N'*f=comma9. mean='Pct'*f=percent6.1), cbsatype all='Total' ; Table TotPop * (sum='N'*f=comma11.) , cbsatype all='Total' ; table earnings*median*f=dollar7. travelTimeToWork*mean*f=comma5.1, cbsatype all='Total'; run;