x cd /pub/data/irsmig/Tools; %let pgm=cnvt_irsmig_countiesB; filename pgm "&pgm..sas"; *---Read the IRS migration file at county-to-county level from the .dat files we got from Matt H (MO FSCPE person) 7/11 with 0809 state level data. 07-19-11: See setup in cnvt_irsmig.sas, where we read the .csv files direct from IRS and create the base datasets. ---; title "&pgm -- Convert Data from IRS on Characteristics of Migrating Tax Returners"; libname irsmig '/pub/data/irsmig'; %let years=0809; %let year1=%substr(&years,1,2); %let year2=%substr(&years,3,2); %let state=29; %let stab=mo; filename inflows "../County-to-County In-Migration Flows File &year1.-&year2. &stab..dat"; filename outflows "../County-to-County Out-Migration Flows File &year1.-&year2. &stab..dat"; missing d; *----Process inmigrations---------------------; data irsmig.&stab.inmig&years(label="Migrations INTO &stab for years &years"); Years="&years"; length ToAreaName $64 ToCounty FromCounty $5 ToSumlev FromSumLev $3 ToState $2 ToCnty $3 FromState $2 FromCnty $3 FromStab $2 FromAreaName $64 NReturns NExemptions 4 TotalIncome 8 MedianIncome 4 AvgHHIncome PerCapitaIncome 4; label TotalIncome='Aggregate Adjusted Gross Income ($000)' NReturns='# Tax Returns' NExemptions='# Exemptions on Tax Returns' MedianIncome='Median Gross Income per Return' AvgHHIncome='Average Gross Income Per Return' PerCapitaIncome='Average Gross Income Per Exemption'; *<--maybe a misleading name----; infile inflows ; input @1 ToState $2. +1 ToCnty $3. +1 FromState $2. +1 FromCnty $3. +1 FromStab $2. +1 FromAreaName $18-49 Nreturns 51-59 Nexemptions 60-70 TotalIncome 71-82 MedianIncome 83-91; if nreturns=-1 then nreturns=.; if nexemptions=-1 then nexemptions=.; if totalincome=-1 then totalincome=.; if medianIncome=-1 then MedianIncome=.; ToState=translate(right(tostate),'0',' '); FromState=translate(right(Fromstate),'0',' '); FromAreaName=propcase(fromareaname); if FromState le '56' then do; if FromCnty='000' then FromSumLev='040'; else FromSumLev='050'; end; else do; FromStab=' '; if fromstate='96' then fromsumlev='tot'; else if fromstate='97' then fromsumlev='tus'; else if fromstate='98' or FromState='57' then fromsumlev='tfo'; end; if tocnty='000' then do; ToAreaName=put(ToState,$state.); ToCounty=ToState; ToSumLev='040'; end; else do; ToCounty=ToState||ToCnty; ToAreaName=put(ToCounty,$county.); ToSumlev='050'; end; FromCounty=FromState||FromCnty; if nreturns then do; AvgHHIncome=round(TotalIncome*1000/Nreturns); PerCapitaIncome=round(TotalIncome*1000/NExemptions); end; format NReturns Nexemptions comma9. TotalIncome comma11. AvgHHIncome PerCapitaIncome MedianIncome dollar8.; label MedianIncome="Median Adjusted Gross Income"; drop _: ; run; proc freq data=irsmig.&stab.inmig&years(keep=years tostate fromstate fromsumlev tosumlev); table tostate*years fromstate fromsumlev tosumlev; title2 "State Freq for irsmig.&stab.inmig&years"; run; *----Process outmigrations---------------------; data irsmig.&stab.outmig&years(label="Migrations OUT OF &stab for years &years"); Years="&years"; length FromAreaName $64 FromCounty ToCounty $5 FromSumlev ToSumLev $3 FromState $2 FromCnty $3 ToState $2 ToCnty $3 ToStab $2 ToAreaName $64 NReturns NExemptions 4 TotalIncome 8 MedianIncome 4 AvgHHIncome PerCapitaIncome 4; label TotalIncome='Aggregate Adjusted Gross Income ($000)' NReturns='# Tax Returns' NExemptions='# Exemptions on Tax Returns' MedianIncome='Median Gross Income per Return' AvgHHIncome='Average Gross Income Per Return' PerCapitaIncome='Average Gross Income Per Exemption'; *<--maybe a misleading name----; infile outflows ; input @1 FromState $2. +1 FromCnty $3. +1 ToState $2. +1 ToCnty $3. +1 ToStab $2. +1 ToAreaName $18-49 Nreturns 51-59 Nexemptions 60-70 TotalIncome 71-82 MedianIncome 83-91; if nreturns=-1 then nreturns=.; if nexemptions=-1 then nexemptions=.; if totalincome=-1 then totalincome=.; if medianIncome=-1 then MedianIncome=.; FromState=translate(right(Fromstate),'0',' '); ToState=translate(right(Tostate),'0',' '); **ToAreaName=propcase(ToAreaname); if ToState le '56' then do; if ToCnty='000' then ToSumLev='040'; else ToSumLev='050'; end; else do; ToStab=' '; if Tostate='96' then ToSumlev='tot'; else if tostate='97' then tosumlev='tus'; else if tostate='98' or ToState='57' then tosumlev='tfo'; end; if fromcnty='000' then do; FromAreaName=put(FromState,$state.); FromCounty=FromState; FromSumLev='040'; end; else do; FromCounty=FromState||FromCnty; FromAreaName=put(FromCounty,$county.); FromSumlev='050'; end; ToCounty=ToState||ToCnty; if nreturns then do; AvgHHIncome=round(TotalIncome*1000/Nreturns); PerCapitaIncome=round(TotalIncome*1000/NExemptions); end; format NReturns Nexemptions comma9. TotalIncome comma11. AvgHHIncome PerCapitaIncome MedianIncome dollar8.; label MedianIncome="Median Adjusted Gross Income"; drop _: ; run; proc freq data=irsmig.&stab.outmig&years(keep=years tostate fromstate fromsumlev tosumlev); table tostate*years fromstate fromsumlev tosumlev; title2 "State Freq for irsmig.&stab.outmig&years"; run;