x cd /pub/data/irsmig/Tools; %let pgm=cnvt_irsmig_statesB; filename pgm "&pgm..sas"; *---Read the IRS migration file at state-to-state level from the .dat files we got from Matt H (MO FSCPE person) 7/11 with 0809 state level data. 07-08-11: See setup in cnvt_irsmig_stabes.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; filename inflows "../si&years.us.dat"; filename outflows "../so&years.us.dat"; missing d; data irsmig.usStateinmig20xxB(label="Migrations INTO all US states for 2004-2005 thru 2008-2009"); if _n_=1 then do __i=1 to _nobsin; ; set irsmig.usStateinmig20xx nobs=_nobsin; output; end; Years="&years"; infile inflows ; input @1 ToState $2. +1 FromState $8-9 FromStab $15-16 FromAreaName $18-49 Nreturns 51-59 Nexemptions 60-70 TotalIncome 71-82 MedianIncome 83-91; 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' or FromState='57' then fromsumlev='tfo'; end; AvgHHIncome=round(TotalIncome*1000/Nreturns); PerCapitaIncome=round(TotalIncome*1000/NExemptions); format NReturns Nexemptions comma9. TotalIncome comma11. AvgHHIncome PerCapitaIncome MedianIncome dollar8.; label MedianIncome="Median Adjusted Gross Income"; ToAreaName=put(ToState,$state.); if tostate='00' then tosumlev='010'; else ToSumLev='040'; output; drop _: ; run; proc freq data=irsmig.usStateinmig20xxB(keep=years tostate fromstate); table tostate*years fromstate; title2 "State Freq for irsmig.usStateinmig20xxB"; run; *------------------------and now process the outmigration data-----------------------------------------; data irsmig.usStateoutmig20xxB(label="Migrations OUT of all US states for 2004-2005 thru 2008-2009"); if _n_=1 then do __i=1 to _nobsin; ; set irsmig.usStateoutmig20xx nobs=_nobsin; output; end; Years="&years"; infile outflows ; input @1 FromState $2. +1 ToState $8-9 ToStab $15-16 ToAreaName $18-49 Nreturns 51-59 Nexemptions 60-70 TotalIncome 71-82 MedianIncome 83-91; 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' or toState='57' then tosumlev='tfo'; end; AvgHHIncome=round(TotalIncome*1000/Nreturns); PerCapitaIncome=round(TotalIncome*1000/NExemptions); format NReturns Nexemptions comma9. TotalIncome comma11. AvgHHIncome PerCapitaIncome MedianIncome dollar8.; label MedianIncome="Median Adjusted Gross Income"; FromAreaName=put(FromState,$state.); if fromstate='00' then fromsumlev='010'; else FromSumLev='040'; output; drop _: ; run; proc freq data=irsmig.usStateoutmig20xxB(keep=years tostate fromstate); table fromstate*years tostate; title2 "State Freq for irsmig.usStateoutmig20xxB"; run;