x cd /pub/data/taxsales/Tools; %let pgm=taxsales_trends; filename pgm "&pgm..sas"; *---Look at taxabe sales data for MO counties over the years 2001-2008 to see what trends can be detected. Coded by J. Blodgett, April, 2009 ----; libname taxsales '/pub/data/taxsales'; libname user '/SAS_temp/user'; title "&pgm.: Combine Multiple Years of MO Taxable Sales Data to Create Trends Dataset"; %let latestyr=08; /* =======================Begin comment================ proc format library=library; %include '/pub/sas/formats/Ssic87nm.sas'/nosource2; run; *---Check to see if we have captured all the sic values in our format code---; data _null_; set taxsales.mosicst08; where siclvl='2'; if put (sic,$sic87nm.)=sic then do; length qsic $5 qsicdesc $45; qsic=quote(sic); qsicdesc=quote(sicdesc); put qsic '=' qsicdesc; end; run; proc print data=taxsales.mosicst08(where=(siclvl='3') keep=siclvl sic sicdesc ); format sic $sic87nm.; run; %macro doset(yr); %do ngeotype=1 %to 2; %if &ngeotype=1 %then %let gt=cnty; %else %let gt=st; %local set; %let set=mosic>.&yr.E; data &set; length Year $4 fipco $5 County $5 SumLev $3 SIC $4 Industry $4 SIClvl $1; set taxsales.mosic>.&yr; by fipco notsorted; array _nac Q1Naccts Q2Naccts Q3Naccts Q4Naccts; array _totac(4) _temporary_; if first.fipco then do _i=1 to 4; *---For some reason they do not report the number of accounts for the total industries line. So we shall calculate them as the sum of all the acounts at the SIC level 2. We initialize these 4 new items to 0 when starting a new geographic area and we add code below to transfer the completed sums when processing the siclvl='0' observation. ---; _totac{_i}=0; end; format Industry $sic87nm.; Industry=sic; _nqswithaccts=0; _totalaccts=0; do _i=1 to 4; if siclvl='0' then _nac{_i}=_totac{_i}; else if siclvl='2' then _totac{_i} + _nac{_i}; if _nac{_i} then do; _Nqswithaccts+1; _totalaccts + _nac{_i}; end; end; Naccts= _totalaccts/_Nqswithaccts; if nmiss(AnSales)=0 then AvgAnSales= AnSales*1000/Naccts; label Naccts='Avg # Accounts for Qtrs w Accts' AvgAnSales='Avg Annual Sales Per Acct ($)'; format AnSales dollar11. AvgAnSales dollar10. Naccts 6.1; format County $mocntye15.; *<---It was specfied as length 13 on some of the earlier data sets but we fix that here---; drop _: ; drop SICdesc Areaname; drop status Q: ; *---We keep no quarterly detail---; run; proc sort data=&set ; by county siclvl sic; run; %end; %*---do ngeotype loop--; %mend doset; options NOmprint; %doset(00); %doset(01); %doset(02); %doset(03); %doset(04); %doset(05); %doset(06); %doset(07); %doset(08); *<-------------------&latestyr should be here. Add 1 each year------------------------------; data rankin; %macro dosets; set %do nyr=0 %to &latestyr; mosiccnty0&nyr.E %end; ; %mend dosets; %dosets; run; data popestbyyr; set popests.mocom&latestyr(keep=county popJL: sumlev where=(sumlev='050')); %macro doloop( ); %local yr yr2; %global latestyr; %do yr=0 %to &latestyr; %let yr2=0&yr; PopEst=PopJL&yr2; Year="20&yr2"; output; %end; %mend doloop; options mprint mlogic; %doloop keep county year PopEst; run; proc sort; by year county; run; data rankin2; merge rankin(in=in1) popestbyyr(in=in2); by year county; if not (in1 and in2) and county le '29510' then do; _nbad+1; if _nbad le 25 then put /'***Non match on county and year**** ' _all_; else abort abend; end; if AnSales then if in2 then SalesPerCap=round( AnSales*1000/PopEst) ; label SalesPerCap='Annual Sales Per Capita' ; format salespercap dollar8.; drop _: ; run; ======================End comment================== */ proc rank data=rankin2 descending out=withsicranks; by year county siclvl; var AnSales ; ranks AnSalesRankbySIC ; run; proc sort data=rankin2 out=rankin3; by year siclvl sic ; run; proc rank data=rankin3 descending out=withcntyranks; by year siclvl sic ; var AnSales SalesPerCap popest; ranks AnSalesRankbyCnty SalesPerCapRankbyCnty PopEstRankbyCnty; run; proc sort data=withsicranks; by year county sic; run; proc sort data=withcntyranks; by year county sic; run; data taxsales.taxsales_ranks(label="Taxable Sales with Ranks by SIC & County 2000 to 20&latestyr"); merge withsicranks(in=in1) withcntyranks(in=in2); by year county sic; if not (in1 and in2) then do; _nbad+1; if _nbad le 20 then put / _all_; else abort abend; drop _nbad; end; label AnSalesRankbySIC='Annual Sales Rank for this SIC'; label AnSalesRankbyCnty='Annual Sales Rank for this County' SalesPerCapRankbyCnty='Per Capita Sales Rank for this County' PopEstRankbyCnty='Pop (Est) Rank for this County'; drop sumlev; format county $mocntye15.; run; data subset; set taxsales.taxsales_ranks; where year='2008' and ( (1 <=AnSalesRankbyCnty<=10) or (1<=AnSalesRankbySIC<=10)); run; proc sort data=subset; by year county siclvl AnSalesRankbySIC; run; options ls=155; proc print data=subset label; by year county; title2 'Subset of taxsales.taxsales_ranks: 2008 obs Where SIC or County Rank is in Top 10'; id sic siclvl industry; run; /* =======================Begin comment================ proc print data=_last_ (obs=200) label ; by year sumlev fipco county; id sic siclvl industry; title2 "&syslast"; run; proc print data=taxsales.mosiccnty00E (obs=200) label ; by year sumlev fipco county; id sic siclvl industry; title2 "taxsales.mosiccnty00E"; run; ======================End comment================== */