x cd /pub/data/irsmig/Tools; %let pgm=cnvt_irsmig_states; filename pgm "&pgm..sas"; /* Read the IRS migration file at state-to-state level. Source: https://www.irs.gov/statistics/soi-tax-stats-migration-data. Go to correct year and download CouState-to-State Outflow and State-to-State Inflow CSV files. 10-21-09: Running with data downloaded from IRS web site with 4 years of data ending with 0708 data. Modeled after comparable setup (cnvt_irsmig) that works with the county mig data. 07-08-11: See setup in cnvt_irsmig_stabesB.sas, where we read the .dat files we got from our FSCPE person. 12-05-11: Processing the 09-10 state data downloaded from irs web site. 04-23-14: Processing the 10-11 state data downloaded from irs web site. Changing variable names for TotalIncome and AvgHHIncome to aggr_AGI and AvgAGI for consistency with the county data starting with 1011 release. 08-05-15: Processing the 2011-12 data. Added code to check for -1 missing values and assigning .d when found. 08-29-15: Processing the 2012-13 data. 10-05-15: Processing the 2013-14 data. (Problem with initial inflows file for 2013-14). 10-17-16: Processing the 2014-2015 data. 11-09-2018: Processing the 2015-2016 data. 01-31-2020: Running the 2016-2017 and 2017-2018 data. 05-28-2021: Running the 2018-2019 data. */ %include '/pub/sas/autoexec.sas'; title "&pgm - Convert Data from IRS on Characteristics of Migrating Tax Returners"; libname irsmig '/pub/data/irsmig'; options nonotes; %let lastyears=%str(2019-20); *<== be sure to edit the csvin and csvout defns, adding new year of data ; missing d; *-- Just add to these lists of concatenated files each year. Small enough that we can just reconvert them all each year. ; filename csvin ( "../stateinflow0405.csv" "../stateinflow0506.csv" "../stateinflow0607.csv" "../stateinflow0708.csv" "../stateinflow0809.csv" "../stateinflow0910.csv" "../stateinflow1011.csv" "../stateinflow1112.csv" "../stateinflow1213.csv" "../stateinflow1314.csv" "../stateinflow1415.csv" "../stateinflow1516.csv" "../stateinflow1617.csv" "../stateinflow1718.csv" "../stateinflow1819.csv" "../stateinflow1920.csv" ); filename csvout ( "../stateoutflow0405.csv" "../stateoutflow0506.csv" "../stateoutflow0607.csv" "../stateoutflow0708.csv" "../stateoutflow0809.csv" "../stateoutflow0910.csv" "../stateoutflow1011.csv" "../stateoutflow1112.csv" "../stateoutflow1213.csv" "../stateoutflow1314.csv" "../stateoutflow1415.csv" "../stateoutflow1516.csv" "../stateoutflow1617.csv" "../stateoutflow1718.csv" "../stateoutflow1819.csv" "../stateoutflow1920.csv" ); data irsmig.usStateinmig20xx(label="Migrations INTO all US states based on returns for multiple years: 2004-05 thru &lastyears"); infile csvin dsd missover eov=_eov; retain _year1 "2003" _year2 "2004"; retain Years " "; label years='Calendar years on which moves are based'; length ToAreaName $64 ToSumlev FromSumLev $3 ToState $2 _ToCnty $3 FromState $2 _FromCnty $3 FromStab $2 ; length FromAreaName $64 NReturns NExemptions 4 aggr_AGI 8 AvgAGI PerCapitaIncome 4; input @1 ToState @; if _eov or _n_= 1 then do; _year1=_year1+1; _year2=_year2+1; years=substr(_year1,3,2)||substr(_year2,3,2); file log; Put 'Begin processing data for ' years; input; _eov=0; delete; *-- Each file has a header record that gets ignored here ; end; label aggr_AGI='Aggregate Adjusted Gross Income ($000)' NReturns='Number of tax returns' NExemptions='Number of exemptions on tax returns' AvgAGI='Average Gross Income per return' PerCapitaIncome='Averge Gross Income per exemption'; *<-- maybe a misleading name ; if _year1 le "2010" then input _tocnty -- aggr_AGI; else input FromState FromStab -- aggr_agi; if ToState ne ' '; ToState=translate(right(tostate),'0',' '); FromState=translate(right(Fromstate),'0',' '); FromAreaName=propcase(fromareaname); if FromState le '56' then FromSumLev='040'; else do; if fromstate='96' then fromsumlev='tot'; else if fromstate='97' then fromsumlev='tus'; else if fromstate='98' then fromsumlev='tfo'; end; if nreturns=-1 then nreturns=.d; if nexemptions=-1 then nexemptions=.d; if aggr_agi=-1 then aggr_agi=.d; AvgAGI=round(aggr_AGI*1000/Nreturns); PerCapitaIncome=round(aggr_AGI*1000/NExemptions); format NReturns Nexemptions comma9. aggr_AGI comma11. AvgAGI PerCapitaIncome dollar8.; ToAreaName=put(ToState,$state.); if tostate='00' then tosumlev='010'; else ToSumLev='040'; drop _: ; run; /* proc contents data=irsmig.usstateinmig20xx position ; run; proc print data=irsmig.usstateinmig20xx(obs=100); by years; id tostate; title2 "irsmig.usstateinmig20xx"; run; proc freq data=irsmig.usStateinmig20xx(keep=years tostate fromstate); table tostate*years fromstate; title2 "State freq for irsmig.usStateinmig20xx"; run; */ data irsmig.usStateoutmig20xx(label="Migrations OUT OF all US states based on returns for multiple years: 2004-05 thru &lastyears"); infile csvout dsd missover eov=_eov; retain _year1 "2003" _year2 "2004"; retain Years " "; label years='Calendar years on which moves are based'; length FromAreaName $64 FromSumlev ToSumLev $3 FromState $2 _FromCnty $3 ToState $2 _ToCnty $3 ToStab $2; length ToAreaName $64 NReturns NExemptions 4 aggr_AGI 8 AvgAGI PerCapitaIncome 4; input @1 FromState @; if _eov or _n_= 1 then do; _year1=_year1+1; _year2=_year2+1; years=substr(_year1,3,2)||substr(_year2,3,2); file log; Put 'Begin processing data for ' years; input; _eov=0; delete; *-- each file has a header record that gets ignored here ; end; label aggr_AGI='Aggregate Adjusted Gross Income ($000)' NReturns='Number of tax returns' NExemptions='Number of exemptions on tax returns' AvgAGI='Average Gross Income per return' PerCapitaIncome='Averge Gross Income per exemption'; *-- maybe a misleading name ; if _year1 le "2010" then input _fromcnty -- aggr_AGI; else input ToState ToStab -- aggr_agi; if FromState ne ' '; FromState=translate(right(fromstate),'0',' '); ToState=translate(right(Tostate),'0',' '); ToAreaName=propcase(Toareaname); if ToState le '56' then ToSumLev='040'; else do; if tostate='96' then tosumlev='tot'; else if tostate='97' then tosumlev='tus'; else if tostate='98' then tosumlev='tfo'; end; AvgAGI=round(aggr_AGI*1000/Nreturns); PerCapitaIncome=round(aggr_AGI*1000/NExemptions); format NReturns Nexemptions comma9. aggr_AGI comma11. AvgAGI PerCapitaIncome dollar8.; FromAreaName=put(fromState,$state.); if fromstate='00' then fromsumlev='010'; else fromSumLev='040'; drop _: ; run; /* proc contents data=irsmig.usstateoutmig20xx position ; run; proc print data=irsmig.usstateoutmig20xx; by years; id tostate; where years in("0405","1314"); title2 "irsmig.usstateoutmig20xx"; run; proc freq data=irsmig.usStateoutmig20xx(keep=years tostate fromstate); table fromstate*years tostate; title2 "State freq for irsmig.usStateoutmig20xx"; run; */