x cd /pub/data/acs/Tools; %let pgm=appEducationByAgeMoHouse; filename pgm "&pgm..sas"; *---Variation of appEducationByAge setup where we read in table b15001 for Mo House Districts. SO: we extract data from the 2012 vintage Missouri base table B15001. We want the count of persons aged 45+ with at least a high school diploma. Merge this data with median HH income data. Per request from user L Salerno 10/14. See setup appEducationByAge where we ran this with Mo Places within county. ---*; libname user '/SAS_temp/user'; filename csvin '/pub/data/acs2012/basetbls/b15001_moHouse.csv'; libname btabs5 '/pub/data/acs2012/btabs5yr'; %libname(acs2012); libname temp '/pub/data2/temp' ; data btabs5.b15001Mohouse(label='Table B15001 for MO House Districts (620 SumLev - 2012 vintage)'); infile csvin dsd firstobs=3 termstr=crlf lrecl=32760; length geoid $16 SumLev $3 State $2 sldl $3 areaname $40 esriid $5 default=5; %macro b15vars; %do i=1 %to 83; b15001i&i b15001m&i %end; %mend b15vars; input geoid esriid areaname %b15vars ; sumlev=substr(geoid,1,3); state=substr(esriid,1,2); sldl=substr(esriid,3,3); if _n_ le 3 then put / _all_; run; *----Step 1: Pull counts of "educated seniors". Not exactly, of course.---; data educ; set btabs5.b15001Mohouse(keep=sumlev esriid areaname b15001i:); Over45HSgrad=sum(of b15001i30-b15001i34 b15001i38-b15001i42 b15001i71-b15001i75 b15001i79-b15001i83); *---These next 2 we begin by calculating exactly the level, but then below we add things to make them "...or more" measures---; Over45Somec=sum(of b15001i31 b15001i39 b15001i72 b15001i80); Over45Bdegree=sum(of b15001i32 b15001i40 b15001i73 b15001i81 b15001i33 b15001i41 b15001i74 b15001i82); Over45Gradpro=sum(of b15001i34 b15001i42 b15001i75 b15001i83); label Over45somec='Some College or more (over 45)' Over45bdegree='Bachlrs degree or more (over 45)'; *--make them all cumulative (...or more) measures--; Over45bdegree+Over45gradpro; Over45somec+Over45bdegree; Over45=sum(of b15001i27 b15001i35 b15001i68 b15001i76); **if Over45HSgrad >= 500 ; PctOver45HSgrad=100*Over45HSgrad/Over45; PctOver45Somec=100*Over45Somec/Over45; PctOver45Bdegree=100*Over45Bdegree/Over45; PctOver45Gradpro=100*Over45GradPro/Over45; *if pctover45hsgrad >= 25; drop b15:; format pct: 5.1; run; proc sort; by esriid; run; data _null_; set acs2012.usstcnty5yr(keep=sumlev state medianhhinc); where sumlev='040' and state='29'; call symput ('statemedian',put(medianHHInc,6.)); stop; run; %put Statemedian=&statemedian; data income; set acs2012.uscdslds5yr(keep=sumlev esriid medianhhinc state where=(state='29' and sumlev='620')); *** and (medianhhinc >= .8* &Statemedian.) )); HHIncRatio=medianhhinc/&statemedian; format HHincRatio 5.3; run; proc sort; by esriid; run; data temp.&pgm; merge educ(in=in1) income(in=in2); by esriid; if in1 and in2; run; ods html file="&pgm..html"; proc print label data=temp.&pgm (drop=state sumlev); title "&pgm.: State House District Level Data With Education and Income Data"; title2 'All Pcts Use Persons Over 45 as Denominator'; id areaname; var over45 medianhhinc pctover45bdegree pctover45gradpro pctover45somec pctover45hsgrad; var over45bdegree over45gradpro over45somec over45hsgrad; var medianhhinc HHincRatio; label pctover45bdegree='% At Least Bachelors or Associates' pctover45somec='% At Least Some College' pctover45gradpro='% Graduate or Prof Degree' pctover45hsgrad='% At Least High School'; label medianhhinc='Median HH Income' HHIncRatio='Ratio Income/To State Value'; run; ods html close;