%let name=marijuana_price_map; filename odsout '.'; /* Plotting data from: http://www.priceofweed.com/directory */ %include '../data_vault/proxy.sas'; /* I %include a file that sets the my_proxy macro variable. You won't be able to use my proxy, therefore set your own macro variable, which will be something like the following: %let my_proxy=http://yourproxy.com:80; */ data marijuana_price_data; run; %macro do_state(state); filename temp_url url "http://www.priceofweed.com/prices/United-States/&state..html" proxy="&my_proxy" ; data temp_data (drop=whole_line); infile temp_url pad; length state $50; state=translate("&state",' ','-'); input whole_line $ 1-150; if index(whole_line,'Medium Quality')^=0 then do; input whole_line $ 1-150; format price_per_oz dollar20.2; /* I was importing with dollar12.2 format, but some prices didn't have the .xx cents */ price_per_oz=.; price_per_oz=input(translate(scan(whole_line,3,'<>'),'','$'),best12.); input whole_line $ 1-150; format sample_size comma10.0; sample_size=.; sample_size=scan(whole_line,3,'<>'); output; end; run; data marijuana_price_data; set marijuana_price_data temp_data; format date date9.; date=input("&sysdate",date7.); if state^='' then output; run; %mend; libname here '.'; /* only do this when you want new/fresh data */ /* */ data all_states; set sashelp.us_data; call execute('%do_state('|| translate(trim(left(statename)),'-',' ') ||');'); run; data here.marijuana_price_data; set marijuana_price_data; run; data marijuana_price_data; set here.marijuana_price_data (where=(state not in ('District of Columbia' 'Puerto Rico'))); length my_html $300; my_html= 'title='||quote( trim(left(state))||'0d'x|| trim(left(put(price_per_oz,dollar8.2)))||' per ounce'||'0d'x|| '(based on '||trim(left(put(sample_size,comma8.0)))||' data points)' ); run; proc sql noprint; select unique date format=nldate. into :date separated by ' ' from marijuana_price_data; quit; run; data my_map; set mapsgfk.us (rename=(state=fip)); length state $50; state=fipnamel(fip); run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS html path=odsout body="&name..htm" (title="Marijuana Prices") style=htmlblue; goptions gunit=pct ftitle='albany amt/bold' ftext='albany amt' htitle=4.5 htext=2.2; goptions ctext=gray33; pattern1 v=s c=cxffffcc; pattern2 v=s c=cxc2e699; pattern3 v=s c=cx78c679; pattern4 v=s c=cx31a354; pattern5 v=s c=cx006837; legend1 label=(position=top font='albany amt/bold' h=2.8 'Price per ounce:') shape=bar(.15in,.15in); title1 ls=1.5 "Average Marijuana Prices"; proc gmap data=marijuana_price_data map=my_map; id state; note link='http://www.priceofweed.com/' move=(27,89) h=2.8 "Data source: priceofweed.com (&date)"; format price_per_oz dollar8.0; choro price_per_oz / levels=5 /*midpoints=old range*/ legend=legend1 coutline=gray33 html=my_html des='' name="&name"; run; proc rank data=marijuana_price_data out=marijuana_price_data groups=5 ties=high; var price_per_oz; ranks quintile_bin; run; axis1 label=none value=(j=right); axis2 label=('Price per ounce') style=0 order=(0 to 350 by 50) minor=none offset=(0,0); goptions ypixels=800 htitle=3.5 htext=1.5; title2 link='http://www.priceofweed.com/' ls=0.8 h=1.8 "Data source: priceofweed.com (&date)"; ods html anchor='bar'; proc gchart data=marijuana_price_data; format price_per_oz dollar8.0; hbar state / type=sum sumvar=price_per_oz nostats descending subgroup=quintile_bin nolegend maxis=axis1 raxis=axis2 noframe space=0 coutline=gray33 autoref clipref cref=graydd html=my_html des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;