x cd /pub/data/acspums/Tools; %let pgm=application_srhshlds; filename pgm "&pgm..sas" ; *---the request from Bill Elder via EJC, March, 2007: Look at toal household and senior households (those with head age >= 62 and >= 65) for various characteristics such as -Household cost burden, owner/renter, median hh income, med hhinc <= 60% of state value, telephone & vehicle availability, disability (any), etc. proc tabulate used to display stat summary tables and proc means used to generate datasets. 3-13-07, jgb. Rev for final version, 5-9-07 Add code to get some US totals 5-14-07. 6-27-07: Replaced fixed cost burden break point of 30 (pct) with &burden parm and reran with burden=50 . ----; libname user '/SAS_temp/user'; libname acspums '/pub/data/acspums' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; libname temp '/pub/data/temp'; %let burden=50; *<----this is the number used to define the limit for housing cost burdened----; %let burdnm1=%eval(&burden-1); title 'Tabulations of Households by PUMA Regions Based on 2005 American Community Survey Data'; title2 'Extracted Estimates Based on Public Use Microdata Sample Datasets (a 1% sample)'; footnote h=1 "Run on &sysdate &systime Using Cost Burden Threshold of &burden.%"; options nodate; %macro dopct(num,den); %if &den=%str() %then %let den=TotHHs62; if &den then Pct&num=100*&num/&den; %mend dopct; proc format; value $superp 29100='North' 29200='Mid Missouri' 29300='KC suburban' 29400='KC city' 29500='West S Central/Lake Ozarks' 29600='St. Louis Metro West' 29701='Central & South St Louis County' 29702='St Louis city & North St L County' 29800='Southeast' 29900='Southwest'; Value $ten 1='Own w Mortgage' 2='Own no Mortgage' '3','4'='Rent'; *Value ocpip 1-29='Less than 30' 30-high='30% or more'; *---Running with alternate view of the cost-burdened using 50% instead of 30 ----; Value ocpip 1-&burdnm1="Less than &burden" &burden-high="&burden.% or more"; Value yesno 1='Yes' 0='No '; run; data pumas; set corrlst.uspumas2k; where state='29'; rename puma5=puma; run; proc sort; by puma ; run; data hhlds(drop=pwgtp) persons (drop=wgtp); merge acspums.mohrecs05(in=inh keep=serialno puma wgtp type ten ocpip grpip hincp tel veh ybl where=(type='1' and ten ne ' ')) acspums.moprecs05(in=inp keep=serialno agep ds pwgtp) end=last; by serialno; length PUMA_Area $64; if puma ne lag(puma) then PUMA_Area=puma||' '||put(puma,$mopuma.); retain puma_area; if first.serialno then do; disabled_resident=0; ***Over65_HH= (agep >= 65); Over62_HH= (agep >=62); end; retain disabled_resident Over: ; if ds='1' then disabled_resident=1; if ds='1' then Disabled=1; else Disabled=0; if ten in ('3','4') then ocpip=grpip; *<----ocpip applies to owners and grpip to renters. But we are recoding so that the new ocpip applies to cost burden in either case----; label ocpip='Housing Cost Burden'; ocpipcat=ocpip; label ocpipcat='Housing Cost Burden category'; Nhhs=1; label Nhhs='# Households'; Persons=1; label Persons='Total Persons'; Over62= (agep >= 62); ***Over65=(agep >= 65); label Over62='Person Age 62+?'; *** Over65='Person Age 65+?'; TelInUnit=(tel='1'); VehAvailable = (veh gt 0); if ybl ne ' ' then OldHouse=(ybl in ('7','8','9')); *--i.e. if built before 1960--; label OldHouse='House built before 1960?'; format OldHouse yesno.; if hincp <= .6*41974 then Under_60Pct_MedInc=1; else Under_60Pct_MedInc=0; label Under_60Pct_MedInc='In HH w Income <= 60% State Median'; if last.serialno then output hhlds; output persons; format _numeric_ comma9.; label over62_HH='Household with head age 62+?' TelinUnit='Telephone in Unit?' disabled_resident='HH has disabled resident?' VehAvailable='Vehicle available in Unit?'; run; %macro dorepts(ft); %*---We put this code in a macro with a parm (ft for filetype) that has value html or pdf and indicates what format output files will be generated via ods. ---; title3 'Report 1: Households'; ods listing close; ods &ft file="../temprepts/&pgm.report1.&ft" ; proc tabulate data=hhlds format=comma9.; freq wgtp; class puma_area ten ocpipcat Over62_HH disabled_resident /missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62_HH disabled_resident yesno.; var nhhs ocpip telinunit VehAvailable hincp OldHouse Under_60Pct_MedInc; table all='State Totals' puma_area , ten*(all ocpipcat) Under_60Pct_MedInc*(sum="# HHs"*f=comma9. mean="%"*f=percent7.1) OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 TelInunit='Pct Phone'*mean=' '*f=percent7.1 VehAvailable='Pct w Veh Avail'*mean=' '*f=percent7.1 hincp='HH Income'*median*f=dollar9. Nhhs*sum='Total' ocpip*median*f=6., (Over62_HH all); run; ods &ft close; ods &ft file="../temprepts/&pgm.report2.&ft" ; title3 'Report 2: Persons'; proc tabulate data=persons format=comma9.; freq pwgtp; class puma_area ten ocpipcat Over62 /missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62 yesno.; var persons disabled Under_60: hincp OldHouse; table all='State Totals' puma_area, persons*sum=' '*f=comma9. disabled *sum='# Persons'*f=comma9. disabled* mean='%'*f=percent7.1 Under_60Pct_MedInc*sum='# Persons'*f=comma9. Under_60Pct_MedInc*mean='%'*f=Percent7.1 hincp*median*f=dollar11. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 ten, (Over62 All='All Persons'); run; ods &ft close; *------Replicate above reports but limit data to households and persons who are in HHs w income < 60% of state median--; title3 'Report 1P: Households Below 60% of State Median Income'; ods &ft file="../temprepts/&pgm.report1p.&ft" ; proc tabulate data=hhlds(where=(Under_60Pct_MedInc)) format=comma9.; freq wgtp; class puma_area ten ocpipcat Over62_HH disabled_resident/missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62_HH disabled_resident yesno.; var nhhs ocpip telinunit VehAvailable hincp Under_60Pct_MedInc OldHouse; table all='State Totals' puma_area , ten*(all ocpipcat) Under_60Pct_MedInc*(sum="# HHs"*f=comma9. mean="%"*f=percent7.1) TelInunit='Pct Phone'*mean=' '*f=percent7.1 VehAvailable='Pct w Veh Avail'*mean=' '*f=percent7.1 hincp='HH Income'*median*f=dollar9. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 Nhhs*sum='Total' ocpip*median*f=6., (Over62_HH all); run; ods &ft close; ods &ft file="../temprepts/&pgm.report2p.&ft" ; title3 'Report 2p: Persons Below 60% of State Median Income'; proc tabulate data=persons(where=(Under_60Pct_MedInc)) format=comma9.; freq pwgtp; class puma_area ten ocpipcat Over62 /missing ; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62 yesno.; var persons disabled Under_60: hincp OldHouse; table all='State Totals' puma_area, persons*sum=' '*f=comma9. disabled *sum='# Persons'*f=comma9. disabled* mean='%'*f=percent7.1 Under_60Pct_MedInc*sum='# Persons'*f=comma9. Under_60Pct_MedInc*mean='%'*f=Percent7.1 hincp*median*f=dollar11. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 ten, (Over62 All='All Persons'); run; ods &ft close; %mend dorepts; *-----invoke the macro to generate the reports-----------*; %dorepts(html) ; %dorepts(pdf) ; *-------------------------------Part 2: Create SAS datasets for custom report and mapping-----------------------*; ods listing; *---turn normal listing file destination back on----; data hhlds2; set hhlds; TotHHs=wgtp; TotHHs62=Over62_HH*wgtp; if Over62_HH then do; if ocpip ge &burden then Over62_CostBurdened=wgtp; *<=====================!!!!!==================; if Under_60Pct_MedInc then do; Over62_PoorHH=wgtp; if ocpip ge &burden then do; if ten=2 then OwnHomeClearPoorBurdened62 =wgtp; else if ten=1 then OwnHomeWithMortPoorBurdened62=wgtp; else RentPoorBurdened62=wgtp; end; *--repeat above regardless of cost-burdened to get denominators--; if ten=2 then OwnHomeClearPoorTotal62 =wgtp; else if ten=1 then OwnHomeWithMortPoorTotal62=wgtp; else RentPoorTotal62=wgtp; end; if ocpip ge &burden then do; if ten=2 then OwnHomeClearBurdened62 =wgtp; else if ten=1 then OwnHomeWithMortBurdened62=wgtp; else RentBurdened62=wgtp; end; if ten=2 then OwnHomeClear62 =wgtp; else if ten=1 then OwnHomeWithMort62=wgtp; else Rent62=wgtp; OldHouse62=OldHouse*wgtp; end; *---if ovr62_HH do group--; OldHouse=OldHouse*wgtp; label OldHouse62='Homes Built Pre 1960 w Head over 62'; if Under_60Pct_MedInc then TotPoorHH = wgtp; keep puma TotHHs TotHHs62 -- Rent62 TotPoorHH OldHouse62; run; proc summary data = hhlds2; class puma; var TotHHs -- TotPoorHH; output out=sumout sum=; run; data temp.srhshlds(label="Written by &pgm in acspums/Tools"); length PUMA $5 AreaName $64; set sumout; if OwnHomeClearPoorBurdened62=. then OwnHomeClearPoorBurdened62=0; drop _: ; %dopct(TotHHs62,TotHHs); %dopct(Over62_costBurdened); %dopct(OldHouse62); %dopct(TotPoorHH,TotHHs); %dopct(Over62_PoorHH) %dopct(OwnHomeClear62) %dopct(OwnHomeWithMort62) %dopct(Rent62) %dopct(OwnHomeClearBurdened62,OwnHomeClear62) %dopct(OwnHomeWithMortBurdened62,OwnHomeWithMort62) %dopct(RentBurdened62,Rent62) %dopct(OwnHomeClearPoorBurdened62,OwnHomeClearPoorTotal62) %dopct(OwnHomeWithMortPoorBurdened62,OwnHomeWithMortPoorTotal62) %dopct(RentPoorBurdened62,RentPoorTotal62) format Pct: 5.1; format tot: Over62: Own: Rent: comma9.; if puma=' ' then Areaname='Missouri'; else areaname=put(puma,$mopuma.); run; proc print data=temp.srhshlds; id puma areaname; title2 'temp.srhshlds'; run; *==============================================US by state==================================================*; title .h=1 'Tabulations of Households by States for U.S. Based on 2005 American Community Survey Data'; title2 .h=1 'Extracted Estimates Based on Public Use Microdata Sample Datasets (a 1% sample)'; data ushhlds(drop=pwgtp) uspersons (drop=wgtp); merge acspums.ushrecs05(in=inh keep=st serialno puma wgtp type ten ocpip grpip hincp tel veh ybl where=(type='1' and ten ne ' ')) acspums.usprecs05(in=inp keep=st serialno agep ds pwgtp) end=last; by st serialno; if first.serialno then do; disabled_resident=0; Over62_HH= (agep >=62); end; retain disabled_resident Over: ; if ds='1' then disabled_resident=1; if ds='1' then Disabled=1; else Disabled=0; if ten in ('3','4') then ocpip=grpip; *<----ocpip applies to owners and grpip to renters. But we are recoding so that the new ocpip applies to cost burden in either case----; label ocpip='Housing Cost Burden'; ocpipcat=ocpip; label ocpipcat='Housing Cost Burden category'; Nhhs=1; label Nhhs='# Households'; Persons=1; label Persons='Total Persons'; Over62= (agep >= 62); ***Over65=(agep >= 65); label Over62='Person Age 62+?'; *** Over65='Person Age 65+?'; TelInUnit=(tel='1'); VehAvailable = (veh gt 0); if ybl ne ' ' then OldHouse=(ybl in ('7','8','9')); *--i.e. if built before 1960--; label OldHouse='House built before 1960?'; format OldHouse yesno.; if hincp <= .6*41974 then Under_60Pct_MedInc=1; else Under_60Pct_MedInc=0; label Under_60Pct_MedInc='In HH w Income <= 60% State Median'; if last.serialno then output ushhlds; output uspersons; format _numeric_ comma9.; format st $state.; rename st=State; label over62_HH='Household with head age 62+?' TelinUnit='Telephone in Unit?' disabled_resident='HH has disabled resident?' VehAvailable='Vehicle available in Unit?'; run; /* =======================Begin comment================ %macro usrepts(ft); %*---We put this code in a macro with a parm (ft for filetype) that has value html or pdf and indicates what format output files will be generated via ods. ---; title3 'US Report 1: Households'; ods listing close; ods &ft file="../temprepts/&pgm.usreport1.&ft" ; proc tabulate data=ushhlds format=comma12.; freq wgtp; class state ten ocpipcat Over62_HH disabled_resident /missing; format ten $ten. ocpipcat ocpip.; ; format Over62_HH disabled_resident yesno.; var nhhs ocpip telinunit VehAvailable hincp OldHouse Under_60Pct_MedInc; table all='U.S. Totals' state , ten*(all ocpipcat) Under_60Pct_MedInc*(sum="# HHs"*f=comma9. mean="%"*f=percent7.1) OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 TelInunit='Pct Phone'*mean=' '*f=percent7.1 VehAvailable='Pct w Veh Avail'*mean=' '*f=percent7.1 hincp='HH Income'*median*f=dollar9. Nhhs*sum='Total' ocpip*median*f=6., (Over62_HH all); run; ods &ft close; ods &ft file="../temprepts/&pgm.usreport2.&ft" ; title3 'US Report 2: Persons'; proc tabulate data=uspersons format=comma12.; freq pwgtp; class state ten ocpipcat Over62 /missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62 yesno.; *format state $stab.; var persons disabled Under_60: hincp OldHouse; table all='U.S. Totals' state, persons*sum=' '*f=comma9. disabled *sum='# Persons'*f=comma9. disabled* mean='%'*f=percent7.1 Under_60Pct_MedInc*sum='# Persons'*f=comma9. Under_60Pct_MedInc*mean='%'*f=Percent7.1 hincp*median*f=dollar11. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 ten, (Over62 All='All Persons'); run; ods &ft close; *------Replicate above reports but limit data to households and persons who are in HHs w income < 60% of state median--; title3 'US Report 1P: Households Below 60% of Missouri State Median Income'; ods &ft file="../temprepts/&pgm.usreport1p.&ft" ; proc tabulate data=ushhlds(where=(Under_60Pct_MedInc)) format=comma12.; freq wgtp; class state ten ocpipcat Over62_HH disabled_resident/missing; format ten $ten. ocpipcat ocpip.; ; format Over62_HH disabled_resident yesno.; var nhhs ocpip telinunit VehAvailable hincp Under_60Pct_MedInc OldHouse; table all='U.S. Totals' state , ten*(all ocpipcat) Under_60Pct_MedInc*(sum="# HHs"*f=comma9. mean="%"*f=percent7.1) TelInunit='Pct Phone'*mean=' '*f=percent7.1 VehAvailable='Pct w Veh Avail'*mean=' '*f=percent7.1 hincp='HH Income'*median*f=dollar9. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 Nhhs*sum='Total' ocpip*median*f=6., (Over62_HH all); run; ods &ft close; ods &ft file="../temprepts/&pgm.usreport2p.&ft" ; title3 'Report 2p: Persons Below 60% of State Median Income'; proc tabulate data=uspersons(where=(Under_60Pct_MedInc)) format=comma12.; freq pwgtp; class State ten ocpipcat Over62 /missing ; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over62 yesno.; var persons disabled Under_60: hincp OldHouse; table all='U.S. Totals' State, persons*sum=' '*f=comma9. disabled *sum='# Persons'*f=comma9. disabled* mean='%'*f=percent7.1 Under_60Pct_MedInc*sum='# Persons'*f=comma9. Under_60Pct_MedInc*mean='%'*f=Percent7.1 hincp*median*f=dollar11. OldHouse='Old House (pre-1960)'*mean='%'*f=percent7.1 ten, (Over62 All='All Persons'); run; ods &ft close; %mend usrepts; *-----invoke the macro to generate the reports-----------*; %usrepts(html) ; %**usrepts(pdf) ; ======================End comment================== */ *-------------------------------Part 2: Create SAS datasets for custom report and mapping-----------------------*; ods listing; *---turn normal listing file destination back on----; ***** changed our mind***** proc printo print="&pgm.us.lst" new; run; data ushhlds2; set ushhlds; TotHHs=wgtp; TotHHs62=Over62_HH*wgtp; if Over62_HH then do; if ocpip ge &burden then Over62_CostBurdened=wgtp; if Under_60Pct_MedInc then do; Over62_PoorHH=wgtp; if ocpip ge &burden then do; if ten=2 then OwnHomeClearPoorBurdened62 =wgtp; else if ten=1 then OwnHomeWithMortPoorBurdened62=wgtp; else RentPoorBurdened62=wgtp; end; *--repeat above regardless of cost-burdened to get denominators--; if ten=2 then OwnHomeClearPoorTotal62 =wgtp; else if ten=1 then OwnHomeWithMortPoorTotal62=wgtp; else RentPoorTotal62=wgtp; end; if ocpip ge 20 then do; if ten=2 then OwnHomeClearBurdened62 =wgtp; else if ten=1 then OwnHomeWithMortBurdened62=wgtp; else RentBurdened62=wgtp; end; if ten=2 then OwnHomeClear62 =wgtp; else if ten=1 then OwnHomeWithMort62=wgtp; else Rent62=wgtp; OldHouse62=OldHouse*wgtp; end; *---if ovr62_HH do group--; OldHouse=OldHouse*wgtp; label OldHouse62='Homes Built Pre 1960 w Head over 62'; if Under_60Pct_MedInc then TotPoorHH = wgtp; keep State TotHHs TotHHs62 -- Rent62 TotPoorHH OldHouse62; format State $state.; run; proc summary data = ushhlds2; class state; var TotHHs -- TotPoorHH; output out=sumout sum=; run; data temp.srhshldsus(label="Written by &pgm in acspums/Tools"); length State $2 AreaName $64; set sumout; if OwnHomeClearPoorBurdened62=. then OwnHomeClearPoorBurdened62=0; drop _: ; %macro dopct(num,den); %if &den=%str() %then %let den=TotHHs62; if &den then Pct&num=100*&num/&den; %mend dopct; %dopct(TotHHs62,TotHHs); %dopct(Over62_costBurdened); %dopct(OldHouse62); %dopct(TotPoorHH,TotHHs); %dopct(Over62_PoorHH) %dopct(OwnHomeClear62) %dopct(OwnHomeWithMort62) %dopct(Rent62) %dopct(OwnHomeClearBurdened62,OwnHomeClear62) %dopct(OwnHomeWithMortBurdened62,OwnHomeWithMort62) %dopct(RentBurdened62,Rent62) %dopct(OwnHomeClearPoorBurdened62,OwnHomeClearPoorTotal62) %dopct(OwnHomeWithMortPoorBurdened62,OwnHomeWithMortPoorTotal62) %dopct(RentPoorBurdened62,RentPoorTotal62) format Pct: 5.1; format tot: Over62: Own: Rent: comma9.; if state=' ' then Areaname='United States'; else areaname=put(state,$state.); run; proc print data=temp.srhshldsus ; id State; title3 'Summary of Key Variables for U.S. and States'; run;