x cd /pub/data/acs/Tools; %let pgm=app_delta1; filename pgm "&pgm..sas"; *----NOTE: We added the 2nd %agg step to get in/out totals and then modified the data step to concat the 2 aggout sets. But we are not going to run these steps!!! since apparently they were not really needed. jgb, 8-6-14. ---; *---Pull 5-year based tables ACS data re household income and family poverty---; *--rerunning 6-1- after fix to input CSV file for Illinois--; *---and again 6-12 after getting asked to include sf1 based data and partition into in and out subsets. And cntyname ---; *---and again 7-16 to add 3 new educational attainment variables. ---; libname acs5yr '/pub/data/acs2012/btabs5yr'; libname sf12010x '/pub/data/sf12010x' access=readonly; libname temp '/pub/data/temp'; *<---for access via dexter---; filename outcos '/pub/data/acs/Tools/deltaoutcos.csv'; *--Gary provided this file. We edited slightly. IDs all "out" cos-; filename text 'inout.sas'; *--genfmat macro writes this file.---; data outcos; *--list of fips county codes to ID counties outside the project ("out" status)-; infile outcos dsd missover; input ; retain status 'out'; do i=1 to 7; length fipco $5; fipco=scan(_infile_,i,', '); if length(fipco)=4 then fipco='0'||fipco; if length(fipco)=5 then output; end; keep fipco status; run; proc sort; by fipco; run; %genfmat(setin=outcos,argvars=fipco,arglen=5,labelvar=status,labellen=3,other=in,fmatname=inout,fmatlib=work) ; ***proc format; ***value $inout 'xxxxx'='in' other='out'; *** run cancel; data temp.delta1(label='Created from setup in acs/Tools/app_delta1.sas'); length Areaname $32; merge acs5yr.usstcnty17_20(keep=sumlev county state b19001i1-b19001i17 b19013i1 b19013m1 b19113i1 b19113m1 b17010i1 b17010i2 b17010m1 b17010m2 b19101i1-b19101i17 b17010i1-b17010i41) acs5yr.usstcnty09_16(keep=sumlev county state b09002i1 b09002i9 b09002i15 b15002i1-b15002i35 ); by state sumlev county; where state in ('28','47','05','29','17','21','22' ); TotFam=b17010i1; PoorFam=b17010i2; label b17010i1='Total Families:' b19001i1='Total Households:'; PctPoorFam=100*b17010i2/b17010i1; format pct: 5.1 ; MedianHHInc=b19013i1; MedianFamInc=b19113i1; KidsInHHs=b09002i1; *<---own children < 18----; KidsInSingleParent=b09002i9 + b09002i15; label KindsInSingleParent='Own kids < 18 in 1-parent HHs'; label FamHHsKidsLt5='Fam HHs w Own Kids < 5'; FamHHsKidsLT5=sum(of b17010i5 b17010i6 b17010i12 b17010i13 b17010i18 b17010i19 b17010i25 b17010i26 b17010i b09002i32 b17010i33 b17010i38 b17010i39); PoorFamHHsKidsLT5=sum(of b17010i5 b17010i6 b17010i12 b17010i13 b17010i18 b17010i19); HighSchoolOrLess= sum(of b15002i3-b15002i11 b15002i20-b15002i28); LessThanBachelors=sum(of HighSchoolOrLess b15002i12-b15002i14 b15002i29-b15002i31); BachelorsAndAbove=sum(of b15002i15-b15002i18 b15002i32-b15002i35); Over25=b15002i1; label HighSchoolOrLess='Persons Age 25+ With HS Education or Less'; if (LessThanBachelors + BachelorsAndAbove) ne Over25 then do; put ' ***education attainment check***' / _all_ ; abort abend; end; drop b09002i: ; drop b17010i: ; drop b15002i: ; if length(county)=3 then fipco=state||county; else fipco=county; if sumlev='050' then areaname=put(fipco,$county.); else Areaname=put(state,$state.); if sumlev='040' then fipco=state; inout=put(fipco,$inout3.); if _n_ le 10 then put state= county= fipco= inout=; run; proc sort; by state sumlev fipco; run; data delta1x; set sf12010x.usstcnty(keep=sumlev state county totpop totpop00 popchange pctpopchange white1--pctmultrace); where state in ('28','47','05','29','17','21','22' ); fipco=county; if sumlev='040' then fipco=state; run; proc sort data=delta1x; by state sumlev fipco; run; data temp.deltaIn temp.deltaOut; merge temp.delta1(in=inacs) delta1x(in=insf1); by state sumlev fipco; if not (first.fipco and last.fipco) then put _all_; if inout='in' then output temp.deltaIn; else output temp.deltaout; drop county; run; proc sort data=temp.delta1; by state inout; run; proc print; by state inout; where inout='in'; var fipco county; run; proc freq ; table state*inout; format state $state.; run; options mprint; %agg(aggin=temp.delta1,aggout=aggout, aggby=state inout,agglvl=2, aggvars=_numeric_, means=PctPoorFam, mweights=TotFam,debug=0) %agg(aggin=temp.delta1,aggout=aggout2, aggby=inout,agglvl=1, aggvars=_numeric_, means=PctPoorFam, mweights=TotFam,debug=0) data temp.delta1_aggout2; length State $2 inout $3; set aggout aggout2; attrib MedianHHInc length=5 label='Median HH Income' format=dollar9.; attrib MedianFamInc length=5 label='Median Family Income' format=dollar9.; array intsz (16) _temporary_ (10000 5000 5000 5000 5000 5000 5000 5000 5000 10000 15000 25000 25000 25000 50000 100000); array b19001(16) b19001i2-b19001i17; array b19101(16) b19101i2-b19101i17; %median(intsize=intsz, intvals=b19001,mdn=MedianHHInc) %median(intsize=intsz, intvals=b19101,mdn=MedianFamInc) drop b19013i1 _:; run; proc contents data=temp.delta1_aggout; run; run;