x cd C:\Users\riceg\Desktop\taxsales\Tools; %let pgm=sic_cnty; filename pgm "&pgm..sas"; *---Convert report files showing Missouri taxable sales by 2- and 3-digit SIC cats by county from MO Dept. of Revenue. ***Also does data by state totals now: converts 2 files per year.*** Coded by J. Blodgett, Feb. 2004 Modified 8-1-05, jgb Starting with 04 data, in 2005, we download reports from the internet -e.g. http://www.dorx.mo.gov/publicreports/taxable_sic_report.txt, and we read the state totals report by sic as well as the county by sic. Modified 10-2-06 to convert data for fy05. Modified 6-21-07 to convert data for 2006. Modified 6-23-08 to convert data for 2007. Modified 4-14-09 to convert data for 2008. Modifed 4-16-09 to go back and convert state level data for 2000-2002. We want to complete the collection. Running with 2012 data, 6-24-13. Running with 2013 data, 8-14-14. GPR EDITED CODE 2018-03-26 Running with 2014, 2015, 2016 data, March 26, 2018 (GPR). ----; title1 "Taxable Sales conversion run: &pgm : Missouri Taxable Sales by SIC and County"; libname taxsales 'C:\Users\riceg\Desktop\taxsales'; /* For the $Mocntye format; required for GPR's version. */ %include "Smocntye.sas"/source2; %macro doyear(yr,status=Complete,level=co,crlf=crlf); %if %index (00 01 02,&yr) and &level=co %then %do; filename in "C:\Users\riceg\Desktop\taxsales\sic_cnty&yr..rpt"; %end; %else %do; %*<==============================================; %if &level=co %then %str( filename in "C:\Users\riceg\Desktop\taxsales\sic_county_report&yr..txt"; ); %else %str( filename in "C:\Users\riceg\Desktop\taxsales\sic_state_report&yr..txt"; ); %end; %if &level=co %then %let dset=mosiccnty&yr; %else %let dset=mosicst&yr; data taxsales.&dset(label="MO taxable sales by SIC and County, 20&yr" outrep=LINUX_X86_64); infile in dsd dlm='2c0d'x truncover termstr=&crlf obs=max; attrib Year length=$4 Status length=$12 Fipco length=$5 label='FIPS county code' County length=$5 label='County' format=$mocntye15. 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)' Q4Sales length=8 format=dollar9. label='4th 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' Q4Naccts length=3 label='4th Qtr # accts' ; retain year "20&yr" Status "&status" SumLev '050'; ; input ; retain fipco county Areaname; length _s $160; *<-- may need to adjust this--; if length(_infile_) ge 2; *<-- may need to adjust this--; _s=substr(_infile_,2); *<-- may need to adjust this--; 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); 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; 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; link output; return; end; if substr(_s,5)=:'COUNTY TOTALS' or substr(_s,5)=:'YEAR AMOUNT 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," "); Q1Naccts=.; Q2Naccts=.; Q3Naccts=.; Q4Naccts=.; *---report does not have naccts filled in for all-SIC totals--; link output; return; end; delete; output: array _sales(5) q1sales q2sales q3sales q4sales AnSales; do _i=1 to 5; if _sales(_i) > 0 then _sales(_i)=_sales(_i)*.001; *--converts to thousands of dollars---; end; output; **good idea? *** format q1sales q2sales q3sales q4sales AnSales dollar14.3; return; drop _:; run; proc freq data=taxsales.&dset; table year status siclvl county; title2 "Freqs from taxsales.&dset"; run; %mend doyear; options NOmprint; /* =======================Begin comment================ %doyear(03,level=co); *--finally converting the full year of data inc 4th qtr---*; %doyear(04,level=co); %*oyear(03,status=3 Qtrs only); %doyear(02); %doyear(01); %doyear(00); %doyear(03,level=st); %doyear(04,level=st); %doyear(05,level=co); %doyear(05,level=st); *---06-21-07--; %doyear(06,level=co); %doyear(06,level=st); *---06-23-08--; %doyear(07,level=co); %doyear(07,level=st); *---04-14-09--; %doyear(08,level=co); %doyear(08,level=st); %doyear(00,level=st) %doyear(01,level=st) %doyear(02,level=st) %doyear(00,level=co) %doyear(01,level=co) %doyear(02,level=co) *---06-24-13--; %doyear(12,level=co); %doyear(12,level=st); *---08-14-14--; %doyear(13,level=co,crlf=lf); %doyear(13,level=st,crlf=lf); ======================End comment================== */ *---03-26-2018--; %doyear(14,level=co,crlf=lf); %doyear(14,level=st,crlf=lf); %doyear(15,level=co,crlf=lf); %doyear(15,level=st,crlf=lf); %doyear(16,level=co,crlf=lf); %doyear(16,level=st,crlf=lf);