x cd /pub/data/acspums/Tools; %let pgm=application_srhshlds06; filename pgm "&pgm..sas" ; *---Update of setup in application_srhshlds. Run with 2006 data for multiple age groups and burden thresholds. Make it macro-based to handle the variations. jgb, 10/07. Running 12-03-07 with burden=30 and oldage=65 per Bill request. ----; %let year=2006; %let yr=06; * set median household income for year (got from acs data for Missouri); * %let medhhinc=41974; %let medhhinc=42841; libname user '/SAS_temp/user'; libname acspums '/pub/data/acspums' access=readonly; libname corrlst '/pub/data/corrlst' access=readonly; libname temp '/pub/data/temp'; data pumas; set corrlst.uspumas2k; where state='29'; rename puma5=puma; run; proc sort; by puma ; run; %***let burden=50; *<----this is the number used to define the limit for housing cost burdened----; %macro doit(burden=50,oldage=55); title "Tabulations of Households by PUMA Regions Based on &year American Community Survey Data"; title2 'Extracted Estimates Based on Public Use Microdata Sample Datasets (a 1% sample)'; title3 "Cost Burden Threshold Used: &burden ; Elderly Defined as Persons Aged &oldage and Older"; footnote h=1 "Run on &sysdate &systime "; options nodate; %macro dopct(num,den,age=&oldage); %if &den=%str() %then %let den=TotHHs&age; if &den then Pct&num=100*&num/&den; %mend dopct; %let burdnm1=%eval(&burden-1); 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-&burdnm1="Less than &burden" &burden-high="&burden.% or more"; Value yesno 1='Yes' 0='No '; run; data hhlds(drop=pwgtp) persons (drop=wgtp); merge acspums.mohrecs&yr(in=inh keep=serialno puma wgtp type ten ocpip grpip hincp tel veh ybl where=(type='1' and ten ne ' ')) acspums.moprecs&yr(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); Over&oldage._HH= (agep >=&oldage); 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'; Over&oldage= (agep >= &oldage); ***Over65=(agep >= 65); label Over&oldage='Person Age &oldage.+?'; 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*&medhhinc 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 over&oldage._HH="Household with head age &oldage.+?" TelinUnit='Telephone in Unit?' disabled_resident='HH has disabled resident?' VehAvailable='Vehicle available in Unit?'; run; %do ift=1 %to 2; %if &ift=1 %then %let ft=html; %else %let ft=pdf; %*---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 Over&oldage._HH disabled_resident /missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over&oldage._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., (Over&oldage._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 Over&oldage. /missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over&oldage. 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, (Over&oldage. 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 Over&oldage._HH disabled_resident/missing; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over&oldage._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., (Over&oldage._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 Over&oldage. /missing ; *** label puma1='Super PUMA (region)'; ***format puma1 $superp.; format ten $ten. ocpipcat ocpip.; ; format Over&oldage. 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, (Over&oldage. All='All Persons'); run; ods &ft close; %end; %*--ift macro loop---; *-------------------------------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; TotHHs&oldage.=Over&oldage._HH*wgtp; if Over&oldage._HH then do; if ocpip ge &burden then Over&oldage._CostBurdened=wgtp; *<=====================!!!!!==================; if Under_60Pct_MedInc then do; Over&oldage._PoorHH=wgtp; if ocpip ge &burden then do; if ten=2 then OwnHomeClearPoorBurdened&oldage. =wgtp; else if ten=1 then OwnHomeWithMortPoorBurdened&oldage.=wgtp; else RentPoorBurdened&oldage.=wgtp; end; *--repeat above regardless of cost-burdened to get denominators--; if ten=2 then OwnHomeClearPoorTotal&oldage. =wgtp; else if ten=1 then OwnHomeWithMortPoorTotal&oldage.=wgtp; else RentPoorTotal&oldage.=wgtp; end; if ocpip ge &burden then do; if ten=2 then OwnHomeClearBurdened&oldage. =wgtp; else if ten=1 then OwnHomeWithMortBurdened&oldage.=wgtp; else RentBurdened&oldage.=wgtp; end; if ten=2 then OwnHomeClear&oldage. =wgtp; else if ten=1 then OwnHomeWithMort&oldage.=wgtp; else Rent&oldage.=wgtp; OldHouse&oldage.=OldHouse*wgtp; end; *---if ovr&oldage._HH do group--; OldHouse=OldHouse*wgtp; label OldHouse&oldage.="Homes Built Pre 1960 w Head over &oldage."; if Under_60Pct_MedInc then TotPoorHH = wgtp; keep puma TotHHs TotHHs&oldage. -- Rent&oldage. TotPoorHH OldHouse&oldage.; run; proc summary data = hhlds2; class puma; var TotHHs -- TotPoorHH; output out=sumout sum=; run; data temp.srhshlds&oldage&burden&yr(label="Written by &pgm in acspums/Tools"); length PUMA $5 AreaName $64; set sumout; if OwnHomeClearPoorBurdened&oldage.=. then OwnHomeClearPoorBurdened&oldage.=0; drop _: ; %dopct(TotHHs&oldage.,TotHHs); %dopct(Over&oldage._costBurdened); %dopct(OldHouse&oldage.); %dopct(TotPoorHH,TotHHs); %dopct(Over&oldage._PoorHH) %dopct(OwnHomeClear&oldage.) %dopct(OwnHomeWithMort&oldage.) %dopct(Rent&oldage.) %dopct(OwnHomeClearBurdened&oldage.,OwnHomeClear&oldage.) %dopct(OwnHomeWithMortBurdened&oldage.,OwnHomeWithMort&oldage.) %dopct(RentBurdened&oldage.,Rent&oldage.) %dopct(OwnHomeClearPoorBurdened&oldage.,OwnHomeClearPoorTotal&oldage.) %dopct(OwnHomeWithMortPoorBurdened&oldage.,OwnHomeWithMortPoorTotal&oldage.) %dopct(RentPoorBurdened&oldage.,RentPoorTotal&oldage.) format Pct: 5.1; format tot: Over&oldage.: Own: Rent: comma9.; if puma=' ' then Areaname='Missouri'; else areaname=put(puma,$mopuma.); run; proc print data=temp.srhshlds&oldage&burden&yr; id puma areaname; title3 "temp.srhshlds&oldage&burden&yr"; run; *==============================================US by state==================================================*; title .h=1 "Tabulations of Households by States for U.S. Based on &year American Community Survey Data"; title2 .h=1 'Extracted Estimates Based on Public Use Microdata Sample Datasets (a 1% sample)'; title3 "Age Limt=&oldage / Cost Burden=&burden Data for &year"; data ushhlds(drop=pwgtp) uspersons (drop=wgtp); merge acspums.ushrecs&yr(in=inh keep=st serialno puma wgtp type ten ocpip grpip hincp tel veh ybl where=(type='1' and ten ne ' ')) acspums.usprecs&yr(in=inp keep=st serialno agep ds pwgtp) end=last; by st serialno; if first.serialno then do; disabled_resident=0; Over&oldage._HH= (agep >=&oldage.); 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'; Over&oldage.= (agep >= &oldage.); ***Over65=(agep >= 65); label Over&oldage.="Person Age &oldage.+?"; *** 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 over&oldage._HH="Household with head age &oldage.+?" TelinUnit='Telephone in Unit?' disabled_resident='HH has disabled resident?' VehAvailable='Vehicle available in Unit?'; run; *-------------------------------Part 2 us: 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; TotHHs&oldage.=Over&oldage._HH*wgtp; if Over&oldage._HH then do; if ocpip ge &burden then Over&oldage._CostBurdened=wgtp; if Under_60Pct_MedInc then do; Over&oldage._PoorHH=wgtp; if ocpip ge &burden then do; if ten=2 then OwnHomeClearPoorBurdened&oldage. =wgtp; else if ten=1 then OwnHomeWithMortPoorBurdened&oldage.=wgtp; else RentPoorBurdened&oldage.=wgtp; end; *--repeat above regardless of cost-burdened to get denominators--; if ten=2 then OwnHomeClearPoorTotal&oldage. =wgtp; else if ten=1 then OwnHomeWithMortPoorTotal&oldage.=wgtp; else RentPoorTotal&oldage.=wgtp; end; if ocpip ge 20 then do; if ten=2 then OwnHomeClearBurdened&oldage. =wgtp; else if ten=1 then OwnHomeWithMortBurdened&oldage.=wgtp; else RentBurdened&oldage.=wgtp; end; if ten=2 then OwnHomeClear&oldage. =wgtp; else if ten=1 then OwnHomeWithMort&oldage.=wgtp; else Rent&oldage.=wgtp; OldHouse&oldage.=OldHouse*wgtp; end; *---if ovr&oldage._HH do group--; OldHouse=OldHouse*wgtp; label OldHouse&oldage.="Homes Built Pre 1960 w Head over &oldage."; if Under_60Pct_MedInc then TotPoorHH = wgtp; keep State TotHHs TotHHs&oldage. -- Rent&oldage. TotPoorHH OldHouse&oldage.; format State $state.; run; proc summary data = ushhlds2; class state; var TotHHs -- TotPoorHH; output out=sumout sum=; run; data temp.srhshlds&oldage&burden&yr.us(label="Written by &pgm in acspums/Tools"); length State $2 AreaName $64; set sumout; if OwnHomeClearPoorBurdened&oldage.=. then OwnHomeClearPoorBurdened&oldage.=0; drop _: ; %macro dopct(num,den); %if &den=%str() %then %let den=TotHHs&oldage.; if &den then Pct&num=100*&num/&den; %mend dopct; %dopct(TotHHs&oldage.,TotHHs); %dopct(Over&oldage._costBurdened); %dopct(OldHouse&oldage.); %dopct(TotPoorHH,TotHHs); %dopct(Over&oldage._PoorHH) %dopct(OwnHomeClear&oldage.) %dopct(OwnHomeWithMort&oldage.) %dopct(Rent&oldage.) %dopct(OwnHomeClearBurdened&oldage.,OwnHomeClear&oldage.) %dopct(OwnHomeWithMortBurdened&oldage.,OwnHomeWithMort&oldage.) %dopct(RentBurdened&oldage.,Rent&oldage.) %dopct(OwnHomeClearPoorBurdened&oldage.,OwnHomeClearPoorTotal&oldage.) %dopct(OwnHomeWithMortPoorBurdened&oldage.,OwnHomeWithMortPoorTotal&oldage.) %dopct(RentPoorBurdened&oldage.,RentPoorTotal&oldage.) format Pct: 5.1; format tot: Over&oldage.: Own: Rent: comma9.; if state=' ' then Areaname='United States'; else areaname=put(state,$state.); run; proc print data=temp.srhshlds&oldage&burden&yr.us ; id State; title4 'Summary of Key Variables for U.S. and States'; run; %mend doit; options mprint; %*doit(burden=50,oldage=55); %doit(burden=30,oldage=65);