x cd /pub/data/saipe/Tools; %let pgm=pov20xxss; filename pgm "&pgm..sas" ; /*---A generalization based on the pov2013mo model setup. Here we vary the year and the state of the data. Create series of reports, charts and maps showing for a specified state and year county poverty data per SAIPE data for 2000+. jgb, 1-8-15. Generalized the setup to work for specified states using a doit macro. Some states this wont work because of number of counties--; Some code in this setup borrows from code published in SAS 2009 GF paper by Devi Sekar: http://support.sas.com/resources/papers/proceedings09/232-2009.pdf Rerunning 3-5-15 to use different gmap dataset, individually projected states. Running with 2015 data 12/2016. ---*/; libname saipe '/pub/data/saipe'; libname sasmaps '/pub/sasmaps'; *---our gmap data sets (not the ones that come directly from SAS I) ---; %*let year=2013; %let year=2015; *<---12/2016---; %let nrank=12; /* %let state=06; %let stab=ca; %let statenm=California; *--our pre-macro test case; */ libname temp '/SAS_temp'; goptions device=png fontres=presentation; goptions ftext='Albany AMT/bold' transparency noninterlaced htitle=1.0 ctitle=navy ; %macro doit(state,stab); x cd /pub/data/saipe/pov&year.charts; x mkdir pov&year&stab; %let outpath=%str(/pub/data/saipe/pov&year.charts/pov&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 saipe.usstcnty&year ( where=(state="&state")); length hlink $120; hlink="TITLE='"||trim(areaname) || ": PctPoor=" ||Put(pctpoor,5.1) ||" ' " || "HREF='https://mcdc.missouri.edu/applications/applinks/links.php?g=05000US"||county||"'"; if sumlev='040' then do; county="&state. "; output temp.state&stab; end; else output rankin; if county='02158' then county='02270'; if county='46102' then county='46113'; *-Back to Wade Hampton & Shannon-; drop ciw: ; run; proc rank data=rankin out=temp.rankout&stab ties=low descending; var pctpoor medianhhinc ; ranks pctpoor_rank medianhhinc_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 "Poverty in &statenm &Counties"; footnote c=black "Maps Support MouseOver To Show Area Names & Values, Click Polygon to Follow Links"; footnote2 c=black h=.5 "Source: &year Vintage SAIPE Estimates"; footnote3 c=black h=.5 "From setup in saipe/Tools/&pgm..sas"; ods html body="charts.html" (title="Pov in &statenm &year SAIPE") contents="contents.html" gpath="&outpath" path="&outpath" style=sasweb; ***ods pdf body="&outpath/charts.html" style=sasweb; ods listing close; options nodate; proc sort data=temp.rankout&stab out=ranked&stab; by pctpoor_rank; run; title2 h=1.5 "Report: Poorest &Counties in Rank Order"; proc print label data=ranked&stab; where pctpoor_rank le &nrank; id geocode areaname; var poor pctPoor PctPoor_rank; run; title2 "Bar Chart of Poorest &Counties"; pattern1 c=blue; data chartdata; set temp.rankout&stab temp.state&stab; proc gchart data=chartdata ; format county $county.; where pctpoor_rank le &nrank; hbar county / descending sumvar=pctpoor discrete cframe=lightblue sumlabel="% Poor" frame description="Bar Chart of Poorest &Counties" 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=(pctpoor_rank le &nrank)) all ; id state county; title2 "&statenm &Counties Showing &NRANK Poorest"; choro pctpoor_rank /discrete cempty=black cdefault=white html=hlink description='&stab County Map Showing 12 Poorest Counties'; format pctpoor_rank rankgrp.; pattern1 c=navy; pattern2 c=lightblue; pattern3 c=blue value=m4x45; 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; pattern5 color=blue; id state county; title2 "All &Statenm &Counties Showing Percent Poor (Quintiles)"; choro pctpoor /levels=5 cempty=black cdefault=gray html=hlink description="Map of All &stab &Counties Showing % Poor (Quintiles)"; run; ods html close; ods listing; proc datasets library=work memtype=catalog nolist; delete gseg; *--Prevents build-up of unnecessary entries--; run; quit; %mend doit; *--we also omit Alaska and Louisiana for this run since they dont call their counties counties--; %*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(02 22,names=1); %*dostates(09 10 15 33 44); *--go ahead and do the small states--; %**dostates(29 42,names=1); *---Test run with 2015 data--; %dostates(n=51,names=1); %**dostates(02 46); /*<=========================Comment out===================================== *---------------------Now generate a total US Map Showing the Same PctPoor 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 SAIPE poverty data to create a choro/menu map: menumaps/uscountiesPctpoor20(xx)--; goptions device=png; goptions ftext='Albany AMT/bold' transparency noninterlaced htitle=1.0 ctitle=navy ; %**let outpath=%str(/pub/sasmaps/menumaps/pctpoor&year.b); %let outpath=%str(/pub/data/saipe/pov&year.charts); x cd &outpath; **x rm gmap*; ods html file="uscountiesPctPoorSaipe&year..html" (title="&year PctPoor by County per SAIPE w drilldown") gpath="&outpath" path="&outpath" style=meadow; data mapdata; length esriid $5; set saipe.usstcnty&year.(where=(sumlev='050') keep=sumlev stab county Poor pctpoor medianhhinc); stab=lowcase(stab); esriid=county; length hlink $120; hlink="TITLE='"||trim(put(county,$county.)) || ": PctPoor=" ||Put(pctpoor,5.1) ||" ' " || "href='/data/saipe/pov&year.charts/pov&year."||stab||"/charts.html'"; *---2 counties have new codes starting in 2015, but our map files still have the old codes. To get a match when mapping we change the counties back to their previous values. (Kusivak, AK and Oglala Lakota, SD). Note that we define hlink before doing recode which means the mouseover will display the new names. --; if county='02158' then county='02270'; if county='46102' then county='46113'; *-Back to Wade Hampton & Shannon-; *** "HREF='https://mcdc.missouri.edu/applications/applinks/links.php?g=05000US"||county||"'"; run; proc gmap map=sasmaps.uscountiesProjected data=mapdata annotate=sasmaps.usstatesoutlines; id esriid; choro pctpoor / levels=5 html=hlink; title "Poverty Rate by County - &year SAIPE Estimates"; title2 "With MouseOver ID and Drill Down To State Detailed Charts/maps of Same Data"; footnote h=.7 "Drilldown Takes You To Set of Charts/Maps For a Single State"; footnote2 h=.5 "From Setup in saipe/Tools/pov20xxss.sas"; run; ods html close; ===========================End commented out================================ */