x cd /pub/data/acs/Tools; %let pgm=agebysexraceh; filename pgm "&pgm..sas"; *---Disggregate data in the B01001 tables so that we get cell-based data sets for each acs vintage. Makes it a lot easier to pull data for specified categories. For starters we shall do it for just the 1yr data. Creates data sets: usagebysexraceh&acsyr i.e. us&pgm..&acsyr where &acsyr is a 2-digit ACS vintage. jgb, 1-16-16 Still modifying 2-10-2016. Finally running for 2015 vintage data, 3-10-17. ---*; %*let acsyear=2014; %let todolist=; libname acs '/pub/data/acs'; /*<=========================Comment out===================================== proc format library=acs; Value $age 01=' 0-4' 02=' 5-9' 03='10-14' 04='15-17' 05='18-19' 06='20-24' 07='25-29' 08='30-34' 09='35-44' 10='45-54' 11='55-64' 12='65-74' 13='75-84' 14='85+ '; value $raceh a='White alone' b='Black alone' c='Amrcn Indian etc alone' d='Asian alone' e='Nat Hawn &PI alone' f='Othr race alone' g='2+ races' h='Wht alone, nonHisp' i='Hispanic'; value $ARlvl 0='Neither' 1='raceh' 2='Age' 3='both'; run; *--Now create the "wc" versions of these formats "with codes". Instead of just returning the meaning it returns the code (argument) followed by the label.--; %include '/pub/sas/macros/cnvt2wc.sas'; %cnvt2wc(fname=$age,lenarg=2,library=acs) ; %cnvt2wc(fname=$raceh,lenarg=1,library=acs) ; %cnvt2wc(fname=$ARlvl,lenarg=1,library=acs) ; options fmtsearch=(acs work sasctlgs); proc freq data=acs.usagebysexraceh14(obs=300); format age $agewc. raceh $racehwc. arlvl $arlvlwc.; table age raceh arlvl; run ; *--ran test interactively--; ===========================End commented out================================ */ *options compress=binary; %let compressopt=binary; options compress=&compressopt; options mprint; *--The doem macro is invoked with the doyear macro. It does a lot of the data step processing. ---; %macro doem; %*---Create pair of 14-age slot arrays for total pop comparable to other alpha-suffix tables, (Collapse some detail)--; %do i=1 %to 5; b01001_&i=b01001i%eval(&i+2); %end; b01001_6=b01001i8 + b01001i9 + b01001i10; *--20-24--; b01001_7=b01001i11; *--25-29-; b01001_8=b01001i12; *--30-34--; b01001_9=b01001i13+b01001i14; *--35-44-; b01001_10=b01001i15+b01001i16; *--45-54--; b01001_11=b01001i17+b01001i18+b01001i19; *--55-64--; b01001_12=b01001i20+b01001i21+b01001i22; *--65-74--; b01001_13=b01001i23+b01001i24; *--75-84--; b01001_14=b01001i25; *--85+--; %do i=15 %to 19; b01001_&i=b01001i%eval(&i+12); %end; b01001_20=b01001i32 + b01001i33 + b01001i34; *--20-24--; b01001_21=b01001i35; *--25-29-; b01001_22=b01001i36; *--30-34--; b01001_23=b01001i37+b01001i38; *--35-44-; b01001_24=b01001i39+b01001i40; *--45-54--; b01001_25=b01001i41+b01001i42+b01001i43; *--55-64--; b01001_26=b01001i44+b01001i45+b01001i46; *--65-74--; b01001_27=b01001i47+b01001i48; *--75-84--; b01001_28=b01001i49; *--85+--; array b01m(14) b01001_1 -- b01001_14; array b01f(14) b01001_15 -- b01001_28; *--Output totals across all ages--; age=' '; Male=b01001i2; Female=b01001i26; Total=b01001i1; CumTotal=.; CumMale=.; CumFemale=.; ARlvl='0'; output; retain __:; drop __: ; __Male=Male; __Female=Female; __total=Male + Female; CumMale=0; CumFemale=0; PctMale=100; PctFemale=100; PctTotal=100; do _nage=1 to 14; age=put(_nage,z2.); Male=b01m(_nage); Female=b01f(_nage); Total=Male + Female; CumMale+Male; CumFemale+Female; CumTotal=CumMale + cumFemale; if __Male then PctMale=100*Male/__male; if __female then PctFemale=100*Female/__Female; if __total then PctTotal=100*Total/__total; ARlvl='2'; output; *---Age totals across race---; end; %do j=1 %to 9; *--there are 9 alpha suffixs, a thru i --; %let raceh=%substr(abcdefghi,&j,1); raceh="&raceh"; *--Output totals across all ages within raceh group--; age=' '; Male=b01001&raceh.i2; Female=b01001&raceh.i17; Total=Male + Female; PctMale=100; PctFemale=100; PctTotal=100; CumMale=.; CumFemale=.; CumTotal=.; ARlvl='1'; output; __Male=male; __female=female; __total=total; *--denominator for pct calcs for age/raceh summaries--; array b01&raceh.m(14) b01001&raceh.i3-b01001&raceh.i16; array b01&raceh.f(14) b01001&raceh.i18-b01001&raceh.i31; CumMale=0; CumFemale=0; do _nage=1 to 14; age=put(_nage,z2.); Male=b01&raceh.m(_nage); Female=b01&raceh.f(_nage); Total=Male + Female; if __Male then PctMale=100*Male/__male; else PctMale=.; if __female then PctFemale=100*Female/__Female; else PctFemale=.; if __total then PctTotal=100*Total/__total; else PctTotal=.; CumMale+Male; CumFemale+Female; CumTotal=CumMale + cumFemale; ARlvl='3'; output; end; %end; %*--do j loop over alphasfxs--; %mend doem; *---Base table b01001 has more age detail but we collapse it to match the 14-cohort detail of the alpha-suffix version (b01001A, etc.)---; %macro doyear(acsyear,invoke_dosets=1); %let acsyr=%substr(&acsyear,3,2); %let acsset=usagebysexraceh&acsyr; libname btabs&acsyr "/pub/data/acs&acsyear./basetbls" ; %if &invoke_dosets=2 %then %goto invdset; %*--value of 2 indicates we want to ONLY do the invoke_dosets processing.-; options compress=&compressopt; data acs.&acsset (label="Cell based extract w age sex race/hispanic data, &acsyear 1yr"); length geoid $24; format geoid ; length ARlvl $1; label ARlvl="0=Niether 1=raceh 2=age 3=both"; set btabs&acsyr..ustabs00_07(keep=b01001: geoid State ); length SumLev $3 esriid $16 geocomp Age $2 RaceH $1; *-Decided not to have sex as id variable. Instead: male, female and total vars--; retain Year "&acsyear" Period "1yr"; retain _alphasfxs 'abcdefghi'; SumLev=substr(geoid,1,3); Geocomp=substr(geoid,4,2); esriid=substr(geoid,8); label geocomp='Geographic Component'; *---Start with totals across all race and hispanic cats using the b01001 table---; RaceH=' '; Male=0; Female=0; Total=0; CumMale=0; CumFemale=0; CumTotal=0; %doem ; *keep geoid; *--decided not to...; keep SumLev ARlvl esriid geocomp State age raceh Male Female Total Cum: Year Period; keep PctMale PctFemale PctTotal; label PctMale="% male in this age cohort within raceh group" PctTotal="% pop in the age cohort within raceh group"; format Pct: 5.1; run; libname btabs&acsyr clear; proc datasets library=acs nolist; modify &acsset; index create State; index create SumLev; quit; options fmtsearch=(acs work sasctlgs); proc print data=&syslast (where=(state='29' and raceh in(' ','a','b') and age <='02') ); by year state sumlev notsorted; id esriid age raceh; var _numeric_; format age $age. raceh $raceh.; run cancel; proc freq data=&syslast(where=(state='29')); by state year; table sumlev age raceh; table ARlvl*age*raceh/ missing list; title2 "Mo Freqs from &syslast"; run; options nomprint; %**global invoke_dosets; %invdset: %if &invoke_dosets %then %do; options compress=no; %doset(memname=&acsset,libname=acs, memlabel=, geouniv=United States, units=Nation State PUMA etc, Years=&acsyear, CreatePgm=&pgm, CreateLib=%str(/pub/data/acs/Tools), Keywords=age race sex ACS disaggregated, Description=%nrbquote(For areas of 65k+ in &acsyear we extract cells from B01001 tables), UsageNotes=%nrbquote(), keyvars=sumlev state geocomp arlvl age raceh year, keyfmats=sumlev state geocomp arlvl age raceh |, DataSource=%str(Vintage &acsyear ACS Base Tables B01001), URLmeta= , SortedBy=SumLev Geocomp esriid raceh age, SubType=ageracesex, SetGroup=cellibated, debug=0) %end; %mend doyear; /*<=========================Comment out===================================== %doyear(2010,invoke_dosets=1); %doyear(2011,invoke_dosets=1); %doyear(2012,invoke_dosets=1); %doyear(2013,invoke_dosets=1); %doyear(2014,invoke_dosets=1); ===========================End commented out================================ */ %doyear(2015,invoke_dosets=1); proc datasets library=acs nolist; modify datasets; index delete dataset memname; index create dataset=(libname memname) / unique; index create memname; quit; **include '/pub/sas/macros/gendshtm.sas'; %gendshtm(libname=acs,debug=1,groupby=LatestYear,sortby=descending LatestYear sortprio setgroup memname,runprocc=1);