x cd /pub/data/popests/Tools; %let pgm=pop20xxmapsncharts; filename pgm "&pgm..sas" ; /*---Here we vary the year and the state of the popests uscomYY data. Create series of reports, charts and maps showing for a specified state and year county pop change data with components. jgb, March, 2015 (initial coding) Special rerun 5-15 to see if we can fix problem with LA data. NOTE: in the 2014 and 2013 run we called the subdir where files go pop2014charts. But starting w 2015 we call it popcharts&year . Running (late) June 21 2016 to process vintage year 2015. **rerun charts for WA to see if we can pin down problem. 11-15-16. Problem was the where filter on proc print of 1st report. *--rerun 11-17-16 to specify "descending" on the pctchange bar chart---* Running MARCH 2017 to do 2016 estimates. Change permissions on the popcharts&year directory after embargo lifts . ---*/; %let temp=; *<====during embargo use: %str(temp/); *=============Edit (comment out or include) mkdir stmt below around line 35==; libname popests "/pub/data/popests/&temp"; libname sasmaps '/pub/sasmaps'; *---our gmap data sets (not the ones that come directly from SAS I) ---; **we need to create this subdirectory: (???) **let outpath=%str(/pub/sasmaps/menumaps/pctch1yr&year); %let year=2016; %let yearm1=%eval(&year-1); %let yr=%substr(&year,3,2); %let yrm1=%substr(&yearm1,3,2); %let nrank=12; /* %let state=06; %let stab=ca; %let statenm=California; *--our pre-macro test case; */ libname temp '/SAS_temp/userb'; *---BE SURE to change permissions to 770 during embargo!!!!!!!!!!!!!!!!!!!---; goptions device=png fontres=presentation; goptions ftext='Albany AMT/bold' transparency noninterlaced htitle=1.0 ctitle=navy ; %macro doit(state,stab); %*if &state=11 %then %goto endmac; *<--we do not do DC. Has only 1 "county"--; x cd /pub/data/popests/popcharts&year.; x mkdir pop&year&stab; *<==========comment out for do-over or while in embargo----; %let outpath=%str(/pub/data/popests/popcharts&year./pop&year&stab); %if &state=22 %then %let Counties=Parishes; %else %if &state=02 %then %let Counties=Boroughs; %else %let Counties=Counties; data rankin temp.state&stab; set popests.uscom&yr ( where=(state="&state")); length hlink $180; if scan(areaname,-1) in ('County','Parish') then do; %chopwrd(areaname); end; hlink="TITLE='"||trim(areaname) || ": % Change=" ||left(Put(pctch1yr,5.1)) || " Change="||left(put(popch1yr,5.))||" ' " || "HREF='https://mcdc.missouri.edu/applications/population/change/?c="||county||"'"; if pctch1yr < -1 then intvl=1; else if pctch1yr < 0 then intvl=2; else if pctch1yr<1 then intvl=3; else if pctch1yr < 1.5 then intvl=4; else intvl=5; label intvl='% Change'; if sumlev='040' then do; county="&state. "; output temp.state&stab; end; else output rankin; keep _character_ pctch1yr popch1yr intvl popest; run; proc rank data=rankin out=temp.rankout&stab ties=low descending; var popch1yr pctch1yr popest; ranks popch1yr_rank pctch1yr_rank popest_rank; run; data _null_; set rankin nobs=_nobs; *----Define the &nrank global parm---; if _nobs le 115 then nrank=12; else if _nobs le 159 then nrank=15; else nrank =24; call symput('nrank',put(nrank,2.)); stop; run; title h=1 "Change in Population &yearm1-&year for &statenm &Counties"; footnote c=black "Maps and Charts Support MouseOver To Show Area Names & Values, Click Polygon to Follow Links"; footnote2 c=black h=.5 "Source: &year Vintage Census Bureau Estimates"; footnote3 c=black h=.5 "From setup in popests/Tools/&pgm..sas"; ods html body="charts.html" (title="Pop Ch in &statenm &yearm1-&year") contents="contents.html" gpath="&outpath" path="&outpath" style=sasweb; ods listing close; options nodate; proc sort data=temp.rankout&stab out=ranked&stab; by pctch1yr_rank; run; title2 h=1.5 "Report: Fastest Growing (by %) &Counties in Rank Order"; title3 h=1.5 link='https://mcdc.missouri.edu/data/popests/Queries/uscom15basics.htm' Link To Saved Query to Access Underlying Data; proc print label split='/' data=ranked&stab label; where pctch1yr_rank le &nrank; id fipco areaname pctch1yr_rank; label pctch1yr="% Change/&yearm1-&year" popch1yr="Numeric/Change" pctch1yr_rank=" Rank /Pct Chg" popch1yr_rank=" Rank /Numeric Chg" popest="Estimated Pop/ July 1, &year" popest_rank=" Rank &year/ Estimated/ Pop"; var pctch1yr popch1yr popch1yr_rank popest popest_rank; run; title2 "Bar Chart of Fastest Growing &Counties (% Change)"; pattern1 c=blue; data chartdata; set temp.rankout&stab temp.state&stab; proc gchart data=chartdata ; format county $county.; where pctch1yr_rank le &nrank; hbar county / sumvar=pctch1yr discrete descending cframe=lightblue sumlabel="% Pop Change" frame description="Bar Chart of Fastest Growing &Counties (% Change)" html=hlink; label county='County/State'; run; %if &nrank=12 %then %do; proc format; value rankgrp 1-4='1 to 4' 5-8='5 to 8' 9-12='9 to 12'; ** 13-high='Not in Top 12'; run; %end; %else %do; %*--Value of nrank should be divisible by 3 for this to work. We symput value of nrank in data _null_ step above.--; %let nrank1=%eval(&nrank/3); %let nrank2=%eval(&nrank1*2); %let nrank3=%eval(&nrank1*3); proc format; value rankgrp 1-&nrank1="1 to &nrank1" %eval(&nrank1+1)-&nrank2="%eval(&nrank1+1) to &nrank2" %eval(&nrank2+1)-&nrank="%eval(&nrank2+1) to &nrank"; run; %end; *--remove map dataset filter to specify x < 0 when using projected gmap set--; proc gmap map=sasmaps.&stab.countiesProjected (where=(state="&state" )) data=temp.rankout&stab (where=(popch1yr_rank le &nrank)) all ; id state county; title2 "&statenm &Counties Showing &NRANK Fastest Growing Per " color="red" " Numeric Change"; title3 "&yearm1 to &year"; choro popch1yr_rank /discrete cempty=black cdefault=white html=hlink description="&stab County Map Showing &nrank Fastest Growing &Counties (Numeric Change)";; format popch1yr_rank rankgrp.; pattern1 c=navy; pattern2 c=blue value=m4x45; pattern3 c=lightblue value=m3x45; run; pattern1 c=red; pattern2 c=red value=m4x45; ; pattern3 value=empty; pattern4 color=blue value=m4x45; pattern5 color=blue; proc format; value intvl 1="Loss of more than 1%" 2="Loss of less than 1%" 3="Gain of < 1%" 4="Gain of 1 to 1.5%" 5="Gain of 1.5% or more"; run; proc gmap map=sasmaps.&stab.countiesProjected (where=(state="&state" )) data=temp.rankout&stab; /* pattern1 c=white; pattern2 c=lightgray; ; pattern3 color=blue value=m3n45;pattern4 color=blue value=m3x45; attern5 color=blue; */ id state county; title2 "All &Statenm &Counties Showing " color="red" " Percent Change " color="navy" " in Pop "; title3 "&yearm1 to &year"; format intvl intvl.; choro intvl / discrete cempty=lightgrey html=hlink; label intvl='% Change'; *****choro pctch1yr / discrete cempty=lightgrey html=hlink; ******choro pctch1yr /levels=5 cempty=black cdefault=gray html=hlink description="Map of All &stab &Counties Showing % Change"; run; ods html close; ods listing; proc datasets library=work memtype=catalog nolist; delete gseg; *--Prevents build-up of unnecessary entries--; run; quit; %endmac: %mend doit; /*<=========================Comment out===================================== %**dostates( 01 02 04 05 06 08 12 13 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 45 46 47 48 49 50 51 53 54 55 56,names=1) ; %**dostates(09 10 15 33 44,names=1); *--go ahead and do the small states--; %*dostates(n=51,names=1); *--rerunning 11-17-16---; %**dostates(19,names=1); *-test run 3-22-17--; %dostates(n=51,names=1); *--running 3-23-17---; ===========================End commented out================================ */ options mprint; *---------------------Now generate a total US Map Showing the Same pctch1yr variable but have it double as a "menu map" to allow the user to click within a state and get the state-level report as generated above. -----------------; *---Use the projected counties map file and the latest pop estimates with components to:menu map: menumaps/uscountiesPctpctch1yr20xx-; goptions device=png; goptions ftext='Albany AMT/bold' transparency noninterlaced htitle=1.0 ctitle=navy ; **x mkdir /pub/sasmaps/menumaps/pctch1yr&year ; *<=========================================; %let outpath=%str(/pub/sasmaps/menumaps/pctch1yr&year); *<=========Create this directory before running====================; x cd &outpath; x rm gmap*; ods html file="uscountiespctch1yr&year..html" (title="&year pctch1yr by County per uscom&yr w drilldown") gpath="&outpath" path="&outpath" style=meadow; data mapdata; length esriid $5; set popests.uscom&yr (where=(sumlev='050') keep=sumlev stab county areaname pctch1yr popch1yr ); stab=lowcase(stab); esriid=county; if pctch1yr < -1 then intvl=1; else if pctch1yr < 0 then intvl=2; else if pctch1yr<1 then intvl=3; else if pctch1yr < 1.5 then intvl=4; else intvl=5; label intvl='% Change'; length hlink $160; hlink="TITLE='"||trim(areaname) || ": % Change=" ||left(Put(pctch1yr,5.1)) || "Change="||left(put(popch1yr,5.))||" ' " || "href='/data/popests/popcharts&year./pop&year"||stab||"/charts.html'"; run; pattern1 c=red; pattern2 c=lightred value=m4x45; ; pattern3 value=empty; pattern4 color=lightblue value=m4x45; pattern5 color=blue value=solid; pattern1 c=red; pattern2 c=red value=m4x45; ; pattern3 c=tan value=empty; pattern4 color=blue value=m4x45; pattern5 color=blue; proc format; value pctchvals low-<-1="1 Loss of more than 1%" -1-<0="2 Loss of less than 1%" 0-<1="Gain of < 1%" 1-<1.5="4 Gain of 1 to 1.5%" 1.5-high="5 Gain of 1.5% or more"; value intvl 1="Loss of more than 1%" 2="Loss of less than 1%" 3="Gain of < 1%" 4="Gain of 1 to 1.5%" 5="Gain of 1.5% or more"; run; proc gmap map=sasmaps.uscountiesProjected data=mapdata annotate=sasmaps.usstatesoutlines; id esriid; format pctch1yr pctchvals.; format intvl intvl.; **choro pctch1yr / discrete cempty=lightgrey html=hlink; choro intvl / discrete cempty=lightgrey html=hlink; title "% Change in Population &yearm1.-&year by County"; title2 "With MouseOver ID and Drill Down To State Detailed Charts/maps of Same Data"; footnote h=.9 "Drilldown Takes You To Set of Charts/Maps For a Single State"; footnote2 h=.7 "From Setup in popests/Tools/&pgm..sas"; run; ods html close; *---And now copy the US menumaps page to the current popcharts directory---; x cp &outpath./us*.html /pub/data/popests/popcharts&year./Menumap.html ;