x cd /pub/data/irstaxes/Tools; %let pgm=cnvt_irstaxes_2012; filename pgm "&pgm..sas"; ***almost ready to test the "plus" step. Want to create variable to go with N04470 and A00101 (new) ***; *----Convert and enhance both the ZIP and state/county level CSV files downloaded from the IRS site - tax year 2012 data. http://www.irs.gov/uac/SOI-Tax-Stats-County-Data-2012 http://www.irs.gov/uac/SOI-Tax-Stats-Individual-Income-Tax-Statistics-2012-ZIP-Code-Data-%28SOI%29 We convert to SAS data sets using variable names and labels provided in the Word Docs for these data. Documentation Guide . These data summarize individual tax returns by state and county & sometimes Adjusted Gross Income Group for a specified tax year. The returns reflect residence at the time of filing, typically in the spring of the following calendar year. So 2012 data are based mostly on returns submitted between Feb and April of 2013. Note that when we did the comparable conversions for TY 2011 we had 3 programs: 2 to read the raw cnty and zip data and a 3rd to create the "plus" enhanced data sets. But this time (starting with 2012 TY data) we combine all that processing into this single program. The 3 steps are labeled stcnty1, (processing of original state/county data), zip1 (processing the original zip data) and plus_sets to create the _plus enhanced sets (both both types of geography and both agi/noagi sets. J. Blodgett, OSEDA, under contract with the Missouri Census Data Center. July, 2014. ----*; %let year=2012; *---Income tax year---; %let yr=%substr(&year,3,2); title "&pgm.: Converting IRS Tax Return Data for Tax Year &year"; libname irstaxes '/pub/data/irstaxes'; *--This is where we create the data set(s)---; proc format; *--create a format code for use in assigning the AGI variable--; value $agi 0='0 Total' 1='1 Under $1' 2='2 $1 < $10k' 3='3 $10k < $25k' 4='4 $25k < $50k' 5='5 $50k < $75k' 6='6 $75k < $100k' 7='7 $100k < $200k' 8='8 $200k or more'; value $agizip 0='0 Total' 1='1 Under $25k' 2='2 $25k < $50k' 3='3 $50k < $75k' 4='4 $75k < $100k' 5='5 $100k < $200k' 6='6 $200k or more'; run; ********************Step cnty1: Read and convert raw county data**********************************; options compress=no; %macro docntys(allno); filename csvinall "/pub/data/irstaxes/&yr.cyallagi.csv"; filename csvinno "/pub/data/irstaxes/&yr.cynoagi.csv"; *<---we manually renamed this file (was "allnoagi" as downloaded)-; %local setname; %let setname=uscntys&allno.agi&yr; data irstaxes.&setname (label="Income Tax data by State and county for tax year &year &allno AGI Groups" ); length State Stab $2 _cnty $3 County $5 AreaName $18 agi_stub $1 agi $15 SumLev $3; retain TaxYear "&year"; *--3 new variables for 2012 (vs 2011): MARS1, MARS4, A00101 --*; Length N1 MARS1 MARS2 MARS4 PREP N2 NUMDEP A00100 N00200 A00200 N00300 A00300 N00600 A00600 N00650 A00650 N00900 A00900 SCHF N01000 A01000 N01400 A01400 N01700 A01700 N02300 A02300 N02500 A02500 N03300 A03300 N04470 A00101 A04470 N18425 A18425 N18450 A18450 N18500 A18500 N18300 A18300 N19300 A19300 N19700 A19700 N04800 A04800 N07100 A07100 N07220 A07220 N07180 A07180 N07260 A07260 N59660 A59660 N59720 A59720 N11070 A11070 N09600 A09600 N06500 A06500 N10300 A10300 N11901 A11901 N11902 A11902 5; Format A0: A1: A5: dollar12. n1 mars2 prep n2 numdep schf N0: N1: N5: comma9.; infile csvin&allno dsd missover firstobs=2 lrecl=2056; input state stab _cnty AreaName agi_stub n1--a11902; if _cnty ne '000' then do; County=state||_cnty; SumLev='050'; **AreaName=put(ZIPcode,$zipname.); end; else do; County='00000'; SumLev='040'; *--Standard code indicating a state level summary--; Areaname=put(state,$state.); end; agi=put(agi_stub,$agi.); drop _cnty; Label County="5-digit County Code " agi_stub="Size of Adj Gross Income" agi="Adj Gross Income Catgry" SumLev="Geo Summary Lvl Code" N1="# Returns" MARS1="# Single Returns" MARS2="# Joint Returns " MARS4="# Head of HH Returns" PREP="# Returns w Paid Preparer Signature" N2="# exemptions [3] " NUMDEP="# dependents " A00100="AGI (Adj Gross Income" N00200="Returns w Salaries & Wages " A00200="Salaries & Wages Amt " N00300="Returns w Taxable Interest " A00300="Taxable Interest Amt " N00600="Returns w Ordinary Dividends " A00600="Ordinary Dividends Amt " N00650="Returns w Qualified Dividens " A00650="Qualified Dividends Amt " N00900="Returns w Business or Professional Net Income (less loss)" A00900="Bus or Prof Net Income Amt " SCHF="# Farm Returns " N01000="Returns w Capital Gain (less loss)" A01000="Capital Gain (less loss) Amt " N01400="Returns w IRA Distributions " A01400="IRA Distributions Amt " N01700="Returns w Taxable Pensions & Annuities " A01700="Taxable Pensions & Annuities Amt " N02300="Returns w Unemployment Compensation " A02300="Unemployment Compensation Amt " N02500="Returns w Taxable Social Security benefits " A02500="Taxable Social Security benefits amt " N03300="Returns w Self-employment Retirement Plans " A03300="Self-employment Retirement Plans Amt " N04470="Returns w Itemized Deductions" A00101="AGI for itemized returns Amt" A04470="Itemized Deductions Amt" N18425="Returns w State & Local Income Tax" A18425="State & Local Income Taxes Amt " N18450="Returns w State & Local General Sales Tax" A18450="State & Local General Sales Tax Amt " N18500="Returns w Real Estate Taxes " A18500="Real Estates Taxes Amt " N18300="Returns w Taxes Paid" A18300="Taxes Paid Amt " ; LABEL N19300="Returns w Mortgage Interest Paid" A19300="Mortgage Interest Paid Amt" N19700="Returns w Contributions" A19700="Contributions Amt " N04800="Returns w Taxable Income" A04800="Taxable Income Amt" N07100="Returns w Total Tax Credits" A07100="Total Tax Credits Amt" N07220="Returns w Child tax credit" A07220="Child Tax Credit Amt" N07180="Returns w Child & Dependent Care Credit" A07180="Child & Dependent Care Credit Amt" N07260="Returns w Additional Child Tax Credit" A07260="Additional Child Tax Credit Amt" N59660="Returns w Earned Income Credit" A59660="Earned Income Credit Amt [6]" N59720="Returns w Excess Earned Income Credit" A59720="Excess Earned Income Credit (refundable) Amt [7]" N11070="Returns with additional child tax credit " A11070="Additional child tax credit Amt" N09600="Returns with alternative minimum tax " A09600="Alternative Minimum Tax Amt " N06500="Returns with income tax " A06500="Income Tax Amt [8] " N10300="Returns with tax liability " A10300="Total Tax Liability [9] " N11901="Returns with tax due at time of filing " A11901="Tax Due at Time of Filing Amt [10] " N11902="Returns with overpayments refunded " A11902="Overpayments Refunded Amt [11]" ; /* ==============================Footnotes copied from the tech doc for 2012 release====================================== G. Endnotes: [1] For complete individual income tax tabulations at the State level, see the historic table posted to Tax Stats at http://www.irs.gov/uac/SOI-Tax-Stats---Historic-Table-2. [2] The County Federal Information Processing System (FIPS) codes used for these statistics were derived from the U.S. Census Bureau. A complete list of codes can be obtained from http://www.census.gov/popest/geographic/codes02.html. [3] Less deficit. [4] “Qualified dividends” are ordinary dividends received in tax years beginning after 2002 that meet certain conditions and receive preferential tax rates. The maximum qualified dividends tax rate is 15%. [5] Includes the Alaskan permanent fund, reported by residents of Alaska on Forms 1040A and 1040EZs. This fund only applies to statistics in the totals, and the state of Alaska. [6] Earned income credit includes both the refundable and non-refundable portions. The non-refundable portion could reduce income tax and certain related taxes to zero. The earned income credit amounts in excess of total tax liability, or amounts when there was no tax liability at all, were refundable. See footnote 7 below for explanation of the refundable portion of the earned income credit. [7] The refundable portion of the earned income credit equals total income tax minus the earned income credit. If the result is negative,this amount is considered the refundable portion. No other refundable credits were taken into account for this calculation. [8] Income tax reflects the amount reported on Form 1040 line 55. It also includes data from Form 1040A and 1040EZ filers. [9] “Total tax liability” differs from “Income tax”, in that “Total tax liability” includes the taxes from recapture of certain prior-year credits, tax applicable to individual retirement arrangements (IRAs), social security taxes on self-employment income and on certain tip income, advanced earned income payments, household employment taxes, and certain other taxes listed in the Form 1040 instructions. [10] Reflects payments to or withholdings made to "Total tax liability". This is the amount the tax filer owes when the income tax return is filed. [11] The amount of overpayments the tax filer requested to have refunded ===================================End Footnotes========================================================================= */; run; options ps=90 ls=160; title2 "Data Per irstaxes.&setname Data Set"; proc print data=irstaxes.&setname(obs=50); title3 "First 50"; by taxyear state stab; id county areaname agi; run; proc means data =irstaxes.&setname n mean sum max; title3 "proc means"; class sumlev agi; run; proc datasets library=irstaxes nolist; modify &setname ; index create state; quit; proc sql; create view irstaxes.mocntys&allno.agi&yr as select * from irstaxes.&setname where state='29'; quit; %mend docntys; %***docntys(all) ; %***docntys(no); ***************************Step 2 (zip1): Read the ZIPcode level CSV files downloaded from the IRS site.*****************; %macro dozips(allno); filename csvinall "/pub/data/irstaxes/&yr.zpallagi.csv"; filename csvinno "/pub/data/irstaxes/&yr.zpnoagi.csv"; *--Had to rename this one. It came down as "allnoagi" options compress=binary; %local setname; %let setname=uszips&allno.agi&yr; data irstaxes.&setname (label="Income Tax data by ZIP Code for tax year &year &allno AGI Groups " ); length State Stab $2 ZIPcode $5 AreaName $40 agi_stub $1 agi $15 SumLev $3; retain TaxYear "&year"; Length N1 MARS1 MARS2 MARS4 PREP N2 NUMDEP A00100 N00200 A00200 N00300 A00300 N00600 A00600 N00650 A00650 N00900 A00900 SCHF N01000 A01000 N01400 A01400 N01700 A01700 N02300 A02300 N02500 A02500 N03300 A03300 N04470 A00101 A04470 N18425 A18425 N18450 A18450 N18500 A18500 N18300 A18300 N19300 A19300 N19700 A19700 N04800 A04800 N07100 A07100 N07220 A07220 N07180 A07180 N07260 A07260 N59660 A59660 N59720 A59720 N11070 A11070 N09600 A09600 N06500 A06500 N10300 A10300 N11901 A11901 N11902 A11902 5; Format A0: A1: A5: dollar12. n1 mars2 prep n2 numdep schf N0: N1: N5: comma9.; infile csvin&allno dsd missover firstobs=2 lrecl=2056; input state stab ZIPCode agi_stub n1--a11902; if zipcode ne '00000' then do; SumLev='871'; AreaName=put(ZIPcode,$zipname.); end; else do; SumLev='040'; *--Standard code indicating a state level summary--; Areaname=put(state,$state.); end; agi=put(agi_stub,$agizip.); Label ZIPcode="5-digit ZIP Code " agi_stub="Size of Adj Gross Income" agi="Adj Gross Income Catgry" SumLev="Geo Summary Lvl Code" N1="# Returns " MARS1="# Single Returns" MARS2="# Joint Returns " MARS4="# Head of HH Returns" PREP="# Returns w Paid Preparer Signature" N2="# exemptions [3] " NUMDEP="# dependents " A00100="AGI (Adj Gross Income" N00200="Returns w Salaries & Wages " A00200="Salaries & Wages Amt " N00300="Returns w Taxable Interest " A00300="Taxable Interest Amt " N00600="Returns w Ordinary Dividends " A00600="Ordinary Dividends Amt " N00650="Returns w Qualified Dividends " A00650="Qualified Dividends Amt " N00900="Returns w Business or Professional Net Income (less loss)" A00900="Bus or Prof Net Income Amt " SCHF="# Farm Returns " N01000="Returns w Capital Gain (less loss)" A01000="Capital Gain (less loss) Amt " N01400="Returns w IRA Distributions " A01400="IRA Distributions Amt " N01700="Returns w Taxable Pensions & Annuities " A01700="Taxable Pensions & Annuities Amt " N02300="Returns w Unemployment Compensation " A02300="Unemployment Compensation Amt " N02500="Returns w Taxable Social Security benefits " A02500="Taxable Social Security benefits amt " N03300="Returns w Self-employment Retirement Plans " A03300="Self-employment Retirement Plans Amt " N04470="Returns w Itemized Deductions" A00101="AGI for itemized returns Amt" A04470="Itemized Deductions Amt" N18425="Returns w State & Local Income Tax" A18425="State & Local Income Taxes Amt " N18450="Returns w State & Local General Sales Tax" A18450="State & Local General Sales Tax Amt " N18500="Returns w Real Estate Taxes " A18500="Real Estates Taxes Amt " N18300="Returns w Taxes Paid" A18300="Taxes Paid Amt " ; LABEL N19300="Returns w Mortgage Interest Paid" A19300="Mortgage Interest Paid Amt" N19700="Returns w Contributions" A19700="Contributions Amt " N04800="Returns w Taxable Income" A04800="Taxable Income Amt" N07100="Returns w Total Tax Credits" A07100="Total Tax Credits Amt" N07220="Returns w Child tax credit" A07220="Child Tax Credit Amt" N07180="Returns w Child & Dependent Care Credit" A07180="Child & Dependent Care Credit Amt" N07260="Returns w Additional Child Tax Credit" A07260="Additional Child Tax Credit Amt" N59660="Returns w Earned Income Credit" A59660="Earned Income Credit Amt [6]" N59720="Returns w Excess Earned Income Credit" A59720="Excess Earned Income Credit (refundable) Amt [7]" N11070="Returns with additional child tax credit " A11070="Additional child tax credit Amt" N09600="Returns with alternative minimum tax " A09600="Alternative Minimum Tax Amt " N06500="Returns with income tax " A06500="Income Tax Amt [8] " N10300="Returns with tax liability " A10300="Total Tax Liability [9] " N11901="Returns with tax due at time of filing " A11901="Tax Due at Time of Filing Amt [10] " N11902="Returns with overpayments refunded " A11902="Overpayments Refunded Amt [11]" ; /* ==============================Footnotes copied from the tech doc for 2012 release====================================== G. Endnotes: [1] For complete individual income tax tabulations at the State level, see the historic table posted to Tax Stats at http://www.irs.gov/uac/SOI-Tax-Stats---Historic-Table-2. [2] Does not include returns with adjusted gross deficit. [3] “Qualified dividends” are ordinary dividends received in tax years beginning after 2002 that meet certain conditions and receive preferential tax rates. The maximum qualified dividends tax rate is 15%. [4] Includes the Alaskan permanent fund, reported by residents of Alaska on Forms 1040A and 1040EZs. This fund only applies to statistics in the totals, and the state of Alaska. [5] Earned income credit includes both the refundable and non-refundable portions. The non-refundable portion could reduce income tax and certain related taxes to zero. The earned income credit amounts in excess of total tax liability, or amounts when there was no tax liability at all, were refundable. See footnote 6 below for explanation of the refundable portion of the earned income credit. [6] The refundable portion of the earned income credit equals total income tax minus the earned income credit. If the result is negative, this amount is considered the refundable portion. No other refundable credits were taken into account for this calculation. [7] Income tax reflects the amount reported on Form 1040 line 55. It also includes data from Form 1040A and 1040EZ filers. [8] “Total tax liability” differs from “Income tax”, in that “Total tax liability” includes the taxes from recapture of certain prior-year credits, tax applicable to individual retirement arrangements (IRA's), social security taxes on self-employment income and on certain tip income, advanced earned income payments, household employment taxes, and certain other taxes listed in the Form 1040 instructions. [9] Reflects payments to or withholdings made to "Total tax liability". This is the amount the tax filer owes when the income tax return is filed. [10] The amount of overpayments the tax filer requested to have refunded. ===================================End Footnotes========================================================================= */; run; options ps=90 ls=160; title2 "Data Per irstaxes.&setname Data Set"; proc print data=irstaxes.&setname(obs=50); title3 "First 50"; by taxyear state stab; id zipcode areaname agi; run; proc means data =irstaxes.&setname n mean sum max; title3 "proc means"; class sumlev agi; run; proc datasets library=irstaxes nolist; modify &setname ; index create state; quit; *---decided not to create mo subset views of these sets---; %mend dozips; %dozips(all) ; %***dozips(no); *---------------------end step 2 (zip1)---------------*; options source; **********************Step 3: Do enhanced ("plus") data sets*******************************************; *---The basic raw data in the files / data sets distributed by the IRS do not contain any variables that seem to us suitable for really getting a handle on the information they contain. Aggregate dollar values and counts of tax returns are only valuable when combined to look at averages, and then compared to some norm such as the corresponding state value for a sub-state area. So this step creates a series of custom "plus" data sets that parallel the original data sets but contain mostly means and percentage values derived from the raw return counts and dollar amounts. We also use mnemonic names in these sets: for example, N00200 is now Nwages and A00200 is now called AmtWages . The new variable AvgWages is calculated by dividing A00200 by N00200 and multiplying by 1000 (since the aggregate amt is in thousands). PctWages is also new and is calculated as the percentage of all returns that reported wages, i.e. 100*N00200/N1 . The new variable AvgTRWages is the average value of Wages if we use Total Returns as the denominator, i.e. it is the average value of wages on all returns, even if they did not report any wages. ***4-10-14: We are alerted to problem with these data. Cases occurred where the Amt and N values were (apparently) 0 but the corresponding Avg variable was showing $1,000. Turns out the apparent 0 values were actually .0001 values, which is what IRS assigns to values that would see better set to 0. See footnote 2 in the tech doc. In this conversion run we shall convert all the .0001 values to 0s and this should make the corresponding Avg variables have missing values. Documention section on Changes indicate that they are no longer using the .0001 value convention to indicate such values. We leave in the code to check for it anyway. ---*; options compress=binary; options mprint; %macro dogeos(geo,allno); %***let geo=cnty; %***let allno=no; %**local setname; %let setname=us&geo.s&allno.agi&yr; data irstaxes.us&geo.splus&allno.agi&yr (label="Enhanced &year Income Tax data by &geo, &allno AGI Grps" ); set irstaxes.&setname; Rename N1=TotRtrns N2=Nexempts MARS1=SNGLRtrns MARS2=MJRtrns MARS4=HHRtrns PREP=PrepRtrns A00100=AmtAGI; if N1 then do; AvgAGI=round(A00100*1000/N1); PctJoint=100*MARS2/N1; PctPrep=100*PREP/N1; AvgExempts=N2/N1; AvgDepends=NUMDEP/N1; Label AvgAGI='Average AGI ($)' A00100='Total AGI ($000)' PctJoint='% Married Couple Joint Returns' PctPrep='% w Paid Preparer Sig' AvgExempts='Avg # Exemptions' AvgDepends='Avg # Dependents'; end; %macro newvar(sfx,name,what); %let lsfx=%length(&sfx); %if &lsfx=3 %then %let sfx=00&sfx; %else %if &lsfx=4 %then %let sfx=0&sfx; if round(n&sfx,.0001)=.0001 then do; n&sfx=0; A&sfx=0; end; N&name=n&sfx; Amt&name=A&sfx; %local pctname; %if %substr(&name,1,4)=%str(With) %then %let pctname=Pct&name; %else %let pctname=PctWith&name; if N1 then &pctname = 100*N&name/N1; if N&name then Avg&name=Amt&name*1000/N&name; if N1 then AvgTR&name=Amt&name*1000/N1; Label N&name="N with &what" Amt&name="Amt &what ($000)"; Label Avg&name="Avg &what when > 0" avgtr&name="Avg &what all returns" &pctname="% reporting &what"; %mend newvar; drop n00200--a11902; %newvar(200,wages,%str(Salaries & Wages)) %newvar(300,TxblInt,Taxable Interest) %newvar(600,OrdDiv,Ordinary Dividends) %newvar(650,QualDv,Qualified Dividends) %newvar(900,BusProInc,Business of Prof Net Income) NFarm=schf; label NFarm='# Farm Returns'; if N1 then PctFarm=100*Nfarm/N1; label PctFarm='% Farm Returns'; %newvar(1000,CapGain,%str(Capital Gain (less loss))) %newvar(1400,IRAdists,IRA Distributions) %newvar(1700,PensionsAnn,Pensions and Annuities) %newvar(2300,UnempComp,Unemployment Compensation) %newvar(2500,TaxableSS,Taxable Social Security Benefits) %newvar(3300,SelfEmpRet,Self Employment Ret Plans) %newvar(4470,Itemized,Itemized Deductions) AmtAGI_Itmzd=A00101; if n04470 then AvgAmtAGI_Itmzd=AmtAGI_Itmzd*1000/N04470; %newvar(18425,LocalIncTaxes,%str(St & Local Income Tax)) %newvar(18450,LocalSalesTaxes,%str(St & Local Sales Tax)) %newvar(18500,RealEstTaxes,Real Estate Taxes) %newvar(18300,TaxesPaid,Taxes Paid) %newvar(19300,MortInt,Mortgage Int Paid) %newvar(19700,Contribs,Contributions) %newvar(04800,TaxableIncome,Taxable Income) %newvar(7100,TaxCreds,Total Tax Credits) %newvar(7220,ChildCreds,Child Tax Credits) %newvar(7180,ChDepCareCreds,%str(Child & Dependent Care Credits)) %newvar(7260,AddChildCreds,Additional Child Tax Credits) %newvar(59660,EarnedIncCreds,Earned Income Credits) %newvar(59720,ExcEarnedIncCreds,Excess Earned Income Credits) %newvar(9600,AltMinTax,Alternate Minimum Tax) %newvar(6500,IncomeTax,Income Tax) %newvar(10300,Liability,Tax Liability[10]) %newvar(11901,TaxDue,Tax Due at Filing[11]) %newvar(11902,Refund,Refund Due[12]) format Pct: 5.1 Avg: dollar9. Amt: dollar11. N: comma9. ; format AvgExempts AvgDepends 4.1; run; %mend dogeos; /*<=========================Comment out===================================== %dogeos(cnty,no) ; %dogeos(cnty,all) ; ===========================End commented out================================ */ %dogeos(zip,no) ; %dogeos(zip,all) ;