x cd /pub/data/acs2009/Tools; %let pgm=employment_by_age_race; filename pgm "&pgm..sas"; *---MCDC env only. Delete line---; *--User request (Fla SDC): "[tabulate] ACS tables B23001 (Sex by age by employment status) and B23002A,..., B23002I (Sex by age by employment status for different races) to quickly calculate the following for any geography (examples): - Unemployment rate by gender (but all age groups) - Unemployment rate for both genders ages 16 to 24 only - Unemployment rate for a particular race (both genders and all age groups) ". We access the relevant tables and generate emplyment-cell data with table counts as weights to be passed to proc tabulate. Tabulate can produce the nice tables. John Blodgett, OSEDA, Missouri Census Data Center. Sept, 2011. --*; title "Unemployment by Age, Race/Ehnicity and Sex Circa 2009 "; *libname acs '/pub/data/acs2009/basetbls'; libname acs '/pub/data/acs2009/test'; libname tools '.'; proc format; value racegrp 0='Total' 1='White Alone' 2='Black Alone' 3='Am Indian Etc Alone' 4='Asian Alone' 5='Nat Hawn & Oth PI Alone' 6='Some Other Race Alone' 7='2 or more races' 8='White Alone, Not Hispanic' 9='Hispanic or Latino' ; value $sex 'M'='Male' 'F'='Female'; run; data tabin; length Areaname $40; set acs.ustabs21_24(keep=geoid sumlev areaname b23001i: b23002: ) ; *----choose a geographic area or set of areas. We choose the nation, one state and one county.----; where geoid in ('01000US', '04000US29','05000US29019'); *<---Choose your geos here---; *---We create cells with dimensions: Geography, AgeCohort, Race/Ethnicity (total and A-I), Employment Status (1 or 0 for yes or no). The geo and race categories overlap but the others do not. ---; attrib RaceGrp length=3 label='Race or ethnic group' format=racegrp.; attrib AgeCohort length=$12 label='Age Cohort'; *----Both the b23001 and b23002X tables are not uniform in that they drop the Armed Forces/Civilian categories for cohorts over 65. So we have two tables for each (4 actually, since we do males and females separately), one for under65 and one for over 65. --; array b23001_u65M{10,7} b23001i3-b23001i72; array b23001_u65F{10,7} b23001i89-b23001i158; array b23001_o65M{3 ,5} b23001i73-b23001i87; array b23001_o65F{3 ,5} b23001i159-b23001i173; *--The b23002X tables have 4 cohorts < 65 and 2 that are over. With 7 data cells for the younger and 5 for the older.--; array b23002_u65M{4,7} b23002i3-b23002i30; array b23002_u65F{4,7} b23002i42-b23002i69; array b23002_o65M{2,5} b23002i31-b23002i40; array b23002_o65F{2,5} b23002i70-b23002i79; array b23002 {79} b23002i1-b23002i79; *---this is a NEW table: there is no b23002 on the input data set.---; array b23002X {9,79} b23002ai1 -- b23002Ii79; *---an array of arrays combinging the 9 alpha-suffix b23002X tables--; *--Process and output cells for the Total group (racegrp=0) ----; Racegrp=0; AgeCohort="16 to 19"; Sex='M'; Unemployed=1; Count=b23001_U65M{1,6}; output; *---Understanding what gets output here is key to the program. We output an observation that corresponds to a new sort of data cell. We specify the cell identifiers (AgeCohort, Sex, RaceGrp and geographic area) and we specify the logical variable Unemployed as being either true (1) or false (0). Then Count is the number of persons occupying the cell. We shall use Count as the FREQ variable for the Proc Tabulate step, so it treats the case as if it occurred in the data set Count times. Then the SUM and MEAN statistics for the Unemployed variable will be the number and the percentage of cases where Unemployed has a value of 1. Which is pretty much just what we want. We have used this stragegy many times over many years. ---; Unemployed=0; Count= b23001_U65M{1,5}; output; *---in armed services no loger being counted as employed. We do CLF only--; Sex='F'; Unemployed=1; Count=b23001_U65F{1,6}; output; Unemployed=0; Count=b23001_U65F{1,5}; output; AgeCohort="20 to 24"; Sex='M'; Unemployed=1; Count=b23001_U65M{2,6} + b23001_U65M{3,6}; output; *--we have to add 2 age cohorts, 20-21 and 22-24 to get 20-24-; Unemployed=0; Count=b23001_U65M{2,5} + b23001_U65M{3,5}; output; Sex='F'; Unemployed=1; Count=b23001_U65F{2,6} + b23001_U65F{3,6}; output; *--we have to add 2 age cohorts, 20-21 and 22-24 to get 20-24-; Unemployed=0; Count=b23001_U65F{2,5} + b23001_U65F{3,5}; output; AgeCohort="25 to 54"; Sex='M'; Unemployed=1; Count=b23001_U65M{4,6} + b23001_U65M{5,6} + b23001_U65M{6,6} + b23001_U65M{7,6}; output; *--we have to add 4 age cohorts, 25-29 thru 45-54 ---; Unemployed=0; Count=b23001_U65M{4,5} + b23001_U65M{5,5} + b23001_U65M{6,5} + b23001_U65M{7,5}; output; Sex='F'; Unemployed=1; Count=b23001_U65F{4,6} + b23001_U65F{5,6} + b23001_U65F{6,6} + b23001_U65F{7,6}; output; *--we have to add 4 age cohorts, 25-29 thru 45-54 ---; Unemployed=0; Count=b23001_U65F{4,5} + b23001_U65F{5,5} + b23001_U65F{6,5} + b23001_U65F{7,5}; output; AgeCohort="55 to 64"; Sex='M'; Unemployed=1; Count=b23001_U65M{8,6} + b23001_U65M{9,6} + b23001_U65M{10,6}; output; *--we have to add 3 age cohorts, 55-59, 60-61 and 62-64 ---; Unemployed=0; Count=b23001_U65M{8,5} + b23001_U65M{9,5} + b23001_U65M{10,5} ; output; Sex='F'; Unemployed=1; Count=b23001_U65F{8,6} + b23001_U65F{9,6} + b23001_U65F{10,6}; output; Unemployed=0; Count=b23001_U65F{8,5} + b23001_U65F{9,5} + b23001_U65F{10,5} ; output; *--- We access the o65 tables to get the 65-69 and 70+ cohorts. The 2nd dimensions change because we have only 5 cells pere age-; AgeCohort="65 to 69"; Sex="M"; Unemployed=1; Count=b23001_o65M{1,4}; output; Unemployed=0; Count=b23001_o65M{1,3}; output; Sex="F"; Unemployed=1; Count=b23001_o65F{1,4}; output; Unemployed=0; Count=b23001_o65F{1,3}; output; AgeCohort="70 and over"; Sex="M"; Unemployed=1; Count=b23001_o65M{2,4} + b23001_o65M{3,4}; output; Unemployed=0; Count=b23001_o65M{2,3} + b23001_o65M{3,3}; output; Sex="F"; Unemployed=1; Count=b23001_o65F{2,4} + b23001_o65F{3,4}; output; Unemployed=0; Count=b23001_o65F{2,3} + b23001_o65F{3,3}; output; do racegrp=1 to 9; do i=1 to 79; b23002{i}=b23002x{racegrp,i}; *--copy the specific alpha-suffix table data cells to the 1-dim table--; end; if b23002i1=. then goto nextrace; *--if the table is suppressed skip it---; AgeCohort="16 to 19"; Sex='M'; Unemployed=1; Count=b23002_U65M{1,6}; output; Unemployed=0; Count=b23002_U65M{1,5}; output; *---in armed services is no longer counted as employed.--; Sex='F'; Unemployed=1; Count=b23002_U65F{1,6}; output; Unemployed=0; Count=b23002_U65F{1,5}; output; *---in armed services is also employed.--; AgeCohort="20 to 24"; Sex='M'; Unemployed=1; Count=b23002_U65M{2,6} ; output; Unemployed=0; Count=b23002_U65M{2,5}; output; Sex='F'; Unemployed=1; Count=b23002_U65F{2,6} ; output; Unemployed=0; Count=b23001_U65F{2,5}; output; AgeCohort="25 to 54"; Sex='M'; Unemployed=1; Count=b23002_U65M{3,6} ; output; Unemployed=0; Count=b23002_U65M{3,5}; output; Sex='F'; Unemployed=1; Count=b23002_U65F{3,6} ; output; Unemployed=0; Count=b23002_U65F{3,5}; output; AgeCohort="55 to 64"; Sex='M'; Unemployed=1; Count=b23002_U65M{4,6} ; output; Unemployed=0; Count=b23002_U65M{4,5}; output; Sex='F'; Unemployed=1; Count=b23002_U65F{4,6} ; output; Unemployed=0; Count=b23002_U65F{4,5}; output; AgeCohort="65 to 69"; Sex='M'; Unemployed=1; Count=b23002_o65M{1,4} ; output; Unemployed=0; Count=b23002_o65M{1,3} ; output; Sex='F'; Unemployed=1; Count=b23002_o65F{1,4} ; output; Unemployed=0; Count=b23002_o65F{1,3} ; output; AgeCohort="70 and over"; Sex='M'; Unemployed=1; Count=b23002_o65M{2,4} ; output; Unemployed=0; Count=b23002_o65M{2,3} ; output; Sex='F'; Unemployed=1; Count=b23002_o65F{2,4} ; output; Unemployed=0; Count=b23002_o65F{2,3} ; output; nextrace: end; *---racegrp do loop---; keep geoid areaname racegrp sex agecohort Unemployed count; run; proc sort; by geoid ; run; proc print data= tabin(obs=50); by geoid ; title2 "Sample Obs from tabin"; run cancel; options pageno=1 nodate; ods output Table=tools.TabulateOutputODSset; ods html file="&pgm..html"; *<-----; title "Unemployment Data Estimated from ACS Data 2009"; title2 "Source: Detailed Tables b23001 and b23002X"; options nodate; proc tabulate data=tabin; by geoid areaname; ** racegrp; format racegrp racegrp. sex $sex.; freq count; *---tabulate each case as if it occurred count times---; class racegrp sex agecohort ; var UNemployed; *--the sum of this variable becomes the number employed in the cell, while the mean becomes the portion employed (the weighted avg of the 0s and 1s is the percentage - a nifty trick.)---; table racegrp* (all='All ages' agecohort), (sex all='Total')* (n="Civilian Labor Force"*f=comma12. unemployed*(sum="# Persons"*f=comma12. mean="Pct"*f=percent7.1 )); footnote .h=1 "Data Not Reported When b23002 Is Suppressed for a Race or Ethnic Group"; footnote2 .h=1 "From Setup in acs2009/Tools/&pgm..sas"; footnote3 .h=1 "Universe is Civilian Labor Force"; footnote4 .h=1 "Missouri Census Data Center - &sysdate"; ; run; **ods html close; ods output close; title2 "Partial Listing of the ODS Output SAS Data Set Created by Proc Tabulate"; proc print data=tools.TabulateOutputODSset(obs=100); run; *<---mcdc env only---;