x cd /pub/data/irsmig/Tools; %let pgm=cnvt_irsmig2; filename pgm "&pgm..sas"; /* Read the IRS migration files, starting with 2011-2012 data. See cnvt_irsmig.sas for setup reading earlier years. See cnvt_irsmig_states.sas for conversion of state level. John Blodgett, Aug, 2015. Source: https://www.irs.gov/statistics/soi-tax-stats-migration-data. Go to correct year and download County-to-County Outflow and County-to-County Inflow CSV files. 08-04-15: Running with 2011-12 data in revised format. 08-13-15: Add code to read the Gross Migration File ( new in 2015). 08-29-15: Running with 2012-13 data. 10-5-15: Running with 2013-14 data. 10-17-16: Running with 2014-2015 data. 11-6-18: Running with 2015-2016 data. 01-31-20: Running with 2016-2017 and 2017-2018 data. 05-28-2021: Running the 2018-2019 data. 05-24-2022: Running the 2019-2020 data. */ title "&pgm - Convert Data from IRS on Characteristics of Migrating Tax Returners"; %include '/pub/sas/autoexec.sas'; libname irsmig '/pub/data/irsmig'; %let debug=0; missing d; %macro addlzs(var); &var=translate(right(&var),'0',' '); %mend addlzs; %macro cnvtfls(years); *-- This macro reads input files and creates SAS datasets for a state or for the US as a whole depending on the single positional parameter passed to it. ; %let calendarYear=20%substr(&years,3,2); %global debug; filename csvin "../countyinflow&years..csv"; filename csvinout "../countyoutflow&years..csv"; %let numvars=Aggr_AGI; %let lennumvars=5; %let lastvarin=Aggr_AGI; data irsmig.usinmig&years(label="Migrations INTO all US counties based on returns for calendar years &years"); infile csvin dsd firstobs=2 missover ; retain Years "&years"; label years='Calendar years on which moves are based'; length ToAreaName $64 ToCounty FromAreaName $64 FromCounty $5 ToSumlev FromSumLev $3 ToState $2 ToCnty $3 FromState $2 ; length FromCnty $3 FromStab $2 _namein $64 NReturns NExemptions 4 &numvars &lennumvars. ; label NReturns='# Tax Returns' NExemptions='# Exemptions on Tax Returns' ; label Aggr_AGI='Aggregate Adjusted Gross Income ($000)' AvgAGI='Avg AGI'; input ToState -- &lastvarin; *-- See the length statement above which defines this variable interval: ToState ToCnty FromState .... ; FromAreaName=_namein; drop _: ; length ToStab $2; if ToState > '00' then ToStab=put(ToState,$fipstab2.); %addlzs(ToState) %addlzs(ToCnty) %addlzs(FromState) %addlzs(FromCnty) if Nreturns=-1 then Nreturns=.d; if Aggr_AGI=-1 then Aggr_AGI=.d; *-- -1 entered to indicate missing value ; if nexemptions=-1 then nexemptions=.d; if Nreturns and Aggr_AGI ne .d then AvgAGI=round(Aggr_AGI*1000/Nreturns); format AvgAGI dollar7. Aggr_AGI comma11.; ToCounty=ToState||ToCounty; if tocnty='000' then select(tostate); when('00') do; ToSumLev='010'; ToAreaName='United States'; end; otherwise do; ToAreaName=put(ToState,$state.); ToSumLev='040'; end; end; else do; ToCounty=ToState||ToCnty; ToAreaName=put(ToCounty,$county.); ToSumlev='050'; end; FromCounty=FromState||FromCnty; Select (FromCounty); when('96000') do; FromSumlev='tot'; FromAreaName='Total migration: US & foreign'; end; when('97000') do; FromSumlev='tus'; FromAreaName='Total migration: US'; end; when('97001') do; FromSumlev='tss'; FromAreaName='Total migration: same state'; end; when('97003') do; FromSumlev='tds'; FromAreaName='Total migration: different state'; end; when('98000') do; FromSumlev='tfo'; FromAreaName='Total migration: foreign'; end; when(ToCounty) do; FromSumlev='050'; FromAreaName='Non-migrants'; end; when('57001') do; FromSumlev='ovs'; FromAreaName='Foreign: overseas'; end; when('57003') do; FromSumlev='fpr'; FromAreaName='Foreign: Puerto Rico'; end; when('57005') do; FromSumlev='apo'; FromAreaName='Foreign: APO/FPO ZIPS'; end; when('57007') do; FromSumlev='fvi'; FromAreaName='Foreign: Virgin Islands'; end; when('58000') do; FromSumlev='oss'; FromAreaName='Other flows: same state'; end; when('59000') do; FromSumLev='ods'; FromAreaName='Other flows: different state'; end; when('59001') do; FromSumLev='ore'; FromAreaName='Other flows: Northeast'; end; when('59003') do; FromSumLev='ore'; FromAreaName='Other flows: Midwest'; end; when('59005') do; FromSumLev='ore'; FromAreaName='Other flows; South'; end; when('59007') do; FromSumLev='ore'; FromAreaName='Other flows: West'; end; when('57009') do; FromSumLev='off'; FromAreaName='Other flows: foreign'; end; *-- redundant?? - same as 98000 ; otherwise do; FromSumLev='050'; if fromstate ne tostate then FromAreaName=trim(FromAreaName)||', '||put(fromstate,$fipstab2.); end; end; if fromsumlev ne '050' then fromstab=' '; %if &debug %then %do; if _n_ le 5 then do; list; put / _all_; end; %end; run; /* proc contents data=irsmig.usinmig&years. position ; run; proc freq data=irsmig.usinmig&years.(keep=tostate); title2 "State Freq for irsmig.usinmig&years.: INmigration Per Tax Year 2000 Returns"; run; */ *-- Now convert the outmigration file to create the outmig dataset ; data irsmig.usoutmig&years.(label="Migrations OUT of all US counties based on returns for calendar years &years" ); infile csvinout dsd firstobs=2 missover; retain Years "&years"; label years='Calendar years on which moves are based'; length FromAreaName $64 FromCounty ToAreaName $64 ToCounty $5 FromSumlev ToSumLev $3 FromState $2 ; length FromCnty $3 ToState $2 ToCnty $3 ToStab $2 _namein $64 NReturns NExemptions 4 &numvars &lennumvars. ; label NReturns='# Tax Returns' NExemptions='# Exemptions on Tax Returns' ; label Aggr_AGI='Aggregate Adjusted Gross Income ($000)' AvgAGI='Avg AGI'; input FromState -- &lastvarin ; if ToState ne ' '; %addlzs(ToState) %addlzs(ToCnty) %addlzs(FromState) %addlzs(FromCnty) ToAreaName=_namein; drop _: ; length FromStab $2; if FromState > '00' then FromStab=put(FromState,$fipstab2.); if Nreturns=-1 then Nreturns=.d; if Aggr_AGI=-1 then Aggr_AGI=.d; *-- -1 entered to indicate missing value ; if nexemptions=-1 then nexemptions=.d; if Nreturns and Aggr_AGI ne .d then AvgAGI=round(Aggr_AGI*1000/Nreturns); format AvgAGI dollar7. Aggr_AGI comma11.; FromCounty=FromState||FromCounty; if fromcnty='000' then select(fromstate); when('00') do; FromSumLev='010'; FromAreaName='United States'; end; otherwise do; FromAreaName=put(FromState,$state.); FromSumLev='040'; end; end; else do; FromCounty=FromState||FromCnty; FromAreaName=put(FromCounty,$county.); FromSumlev='050'; end; ToCounty=ToState||ToCnty; Select (ToCounty); when('96000') do; ToSumlev='tot'; ToAreaName='Total migration: US & foreign'; end; when('97000') do; ToSumlev='tus'; ToAreaName='Total migration: US'; end; when('97001') do; ToSumlev='tss'; ToAreaName='Total migration: same state'; end; when('97003') do; ToSumlev='tds'; ToAreaName='Total migration: different state'; end; when('98000') do; ToSumlev='tfo'; ToAreaName='Total migration: foreign'; end; when(FromCounty) do; ToSumlev='050'; ToAreaName='Non-migrants'; end; when('57001') do; ToSumlev='ovs'; ToAreaName='Foreign: overseas'; end; when('57003') do; ToSumlev='fpr'; ToAreaName='Foreign: Puerto Rico'; end; when('57005') do; ToSumlev='apo'; ToAreaName='Foreign: APO/FPO ZIPS'; end; when('57007') do; ToSumlev='fvi'; ToAreaName='Foreign: Virgin Islands'; end; when('58000') do; ToSumlev='oss'; ToAreaName='Other flows: same state'; end; when('59000') do; ToSumLev='ods'; ToAreaName='Other flows: different state'; end; when('59001') do; ToSumLev='ore'; ToAreaName='Other flows: Northeast'; end; when('59003') do; ToSumLev='ore'; ToAreaName='Other flows: Midwest'; end; when('59005') do; ToSumLev='ore'; ToAreaName='Other flows: South'; end; when('59007') do; ToSumLev='ore'; ToAreaName='Other flows: West'; end; when('57009') do; ToSumLev='off'; ToAreaName='Other flows: foreign'; end; *-- redundant?? - same as 98000 ; otherwise do; ToSumLev='050'; if Tostate ne Fromstate then ToAreaName=trim(ToAreaName)||', '||put(Tostate,$fipstab2.); end; end; if ToSumlev ne '050' then Tostab=' '; run; /* proc freq data=irsmig.usoutmig&years.(keep=fromstate); title2 "State Freq for irsmig.usoutmig&years.: OUT-migration Per calendar Year &calendarYear Returns"; run; */ filename csvin clear; filename csvinout clear; *-- Now create the Missouri subsets of the US datasets ; data irsmig.moinmig&years(label="Missouri subset of usinmig&years"); set irsmig.usinmig&years; where ToState='29'; run; data irsmig.mooutmig&years(label="Missouri subset of usoutmig&years"); set irsmig.usoutmig&years; where FromState='29'; run; %endmac: %mend cnvtfls; *---------------------------------------------------------------------------------; /* %cnvtfls(1112); %cnvtfls(1213); %cnvtfls(1314); %cnvtfls(1415); %cnvtfls(1516); %cnvtfls(1617); %cnvtfls(1718); %cnvtfls(1819); */ %cnvtfls(1920);