x cd /pub/data/taxsales/Tools; %let pgm=sic_cnty_prelim; filename pgm "&pgm..sas"; *--variation on sic_cnty setup that uses preliminary data from the latest year and does estimates by using previous year quarterly data to estimate value for the latest year. jgb, March, 2007 . ----; title1 "Taxable Sales conversion run: &pgm : Missouri Taxable Sales by SIC and County"; libname taxsales '/pub/data/taxsales'; %macro doyear(yr,status=Estimated,level=co); %if &level=co %then %str( filename in "/pub/data/taxsales/sic_county_report&yr._prelim.txt"; ); %else %str( filename in "/pub/data/taxsales/sic_state_report&yr._prelim.txt"; ); %if &level=co %then %let dset=mosiccnty&yr; %else %let dset=mosicst&yr; %local yrm1; %let yrm1=%eval (&yr - 1); %if %length(&yrm1)=1 %then %let yrm1=0&yrm1; %if &level=co %then %let dsetm1=mosiccnty&yrm1; %else %let dsetm1=mosicst&yrm1; data &dset; infile in dsd dlm='2c0d'x truncover obs=max; attrib Year length=$4 Status length=$12 Fipco length=$5 label='FIPS county code' County length=$5 label='County' format=$mocntye. Areaname length=$18 label='Area Name' SumLev length=$3 label='Geo Sum Lvl' SIC length=$3 label='SIC Code' SICdesc length=$32 label='SIC Description' SIClvl length=$1 label='SIC level' AnSales length=8 format=dollar9. label='Annual Taxable Sales ($000)' Q1Sales length=8 format=dollar9. label='1st Qtr Taxable Sales ($000)' Q2Sales length=8 format=dollar9. label='2nd Qtr Taxable Sales ($000)' Q3Sales length=8 format=dollar9. label='3rd Qtr Taxable Sales ($000)' Q1Naccts length=3 label='1st Qtr # accts' Q2Naccts length=3 label='2nd Qtr # accts' Q3Naccts length=3 label='3rd Qtr # accts' ; retain year "20&yr" Status "&status" SumLev '050'; ; input ; retain fipco county Areaname; length _s $165; if length(_infile_) ge 2; _s=substr(_infile_,2); length _word $8; _word=scan(left(_s),1,' '); *<--use first word in the report line to see if we have a data line or a county hdr-; if _word='COUNTY:' then do; length _cnty $3; _cnty=substr(_s,19,3); *---edit ste genevieve county code from 193 to 186 to use the official code----; if _cnty='193' then _cnty='186'; county='29'||_cnty; fipco=county; AreaName=substr(_s,26); ****this was 27 but we were losing first letter of name***; delete; end; %if &level=st %then %do; SumLev='040'; county='29 '; fipco=county; areaname='Missouri'; %end; if _word='YEAR' then _word='---'; if length(_word)=3 and verify(_word,' 0123456789-')=0 then do; *--we recognize that it is a SIC code so we have data to parse--; SIC =_word; if sic='---' then do; SICdesc='Total Establishments '; siclvl=0; end; else do; SICdesc=substr(_s,8,32); if substr(sic,3,1)='-' then siclvl=2; else siclvl=3; end; _s=compress( substr(_s,45) ,'$,') ; *--remove the dollars signs and commas so we have valid numerics--; Q1Sales=scan(_s,1," "); Q1Naccts=scan(_s,2," "); If Q1Sales=0 and Q1Naccts>0 then Q1Sales=.A; Q2Sales=scan(_s,3," "); Q2Naccts=scan(_s,4," "); If Q2Sales=0 and Q2Naccts>0 then Q2Sales=.A; Q3Sales=scan(_s,5," "); Q3Naccts=scan(_s,6," "); If Q3Sales=0 and Q3Naccts>0 then Q3Sales=.A; /* =======================Begin comment================ Q4Sales=scan(_s,7," "); Q4Naccts=scan(_s,8," "); If Q4Sales=0 and Q4Naccts>0 then Q4Sales=.A; AnSales=scan(_s,9," "); if AnSales=0 and max(q1Naccts,q2naccts,q3naccts,q4naccts) then AnSales=.A; ======================End comment================== */ link output; return; end; if substr(_s,5)=:'COUNTY TOTALS' then do; sic='---'; siclvl='0'; sicdesc='--Total--'; _s=compress( substr(_s,39) ,'$,') ; *--remove the dollars signs and commas so we have valid numerics--; Q1Sales=scan(_s,1," "); Q2Sales=scan(_s,2," "); Q3Sales=scan(_s,3," "); *** Q4Sales=scan(_s,4," "); *** AnSales=scan(_s,5," "); link output; return; end; delete; output: array _sales(3) q1sales q2sales q3sales; *** q4sales AnSales; do _i=1 to 3; if _sales(_i) > 0 then _sales(_i)=_sales(_i)*.001; *--converts to thousands of dollars---; end; output; return; drop _:; run; proc sort; by fipco sic; run; proc sort data=taxsales.&dsetm1(keep=fipco sic q4:) out=&dsetm1; by fipco sic; run; data taxsales.&dset(label="MO taxable sales by SIC and County, 20&yr (preliminary estimates)"); update &dset (in=incuryr) &dsetm1; by fipco sic; if incuryr; AnSales=sum(of q1sales q2sales q3sales q4sales); label q4sales="4th quarter sales fr previous FY" q4naccts="4th quarter # accts fr previous FY"; run; proc freq data=taxsales.&dset; table year status siclvl county; title2 "Freqs from taxsales.&dset"; title3 "Estimating 4th Quarter and Annual Sales by Substituting Last Year 4th Quarter Figures"; run; %mend doyear; options mprint; *---03-05-07---; %*doyear(06,level=co); %doyear(06,level=st);