[ad_1]
I am trying to plot two variables on US map. I would like to show price of product A and the difference v/s product B below it inside parenthesis. The code is almost finished. Only problem I am facing is that I am unable to put labels for smaller north eastern states like New Jersey, vermont and Hampshire without them overlapping. I would like something like the attached file wherein the above mentioned states' labels are shown with a line.
Below is the code I have so far.
proc import datafile="../Book8.csv" out=response dbms=csv replace;
run;
proc export data=response outfile="check.csv" dbms=csv replace;
run;
proc sort data=response out=sallx2(drop=Price_B); by STATECODE; run;
proc sort data=maps.us2 out=sus2(keep=STATE STATECODE); by STATECODE; run;
data mapfips;
merge sallx2 (in=a)
sus2 (in=b)
;
by STATECODE;
if a;
run;
data mapfips;
set mapfips;
dummy="$";
dummy1="(";
dummy2=")";
new_Price_A=catx("", of dummy Price_A);
new_Difference=catx("", of dummy1 dummy Difference dummy2);
run;
proc sort data=mapfips out=smapfips; by STATE; run;
proc sort data=maps.uscenter out=suscenter(keep=STATE X Y) nodupkey;
by STATE; run;
data mapfips2;
merge smapfips (in=a)
suscenter (in=b)
;
by STATE;
if a;
run;
data stlabel;
length function $ 8 position $ 1
text $ 20 style $ 30;
set mapfips2;
retain flag 0
xsys ysys '2'
hsys '3' when 'a';
format Difference dollar5.2;
text=new_Difference; style="'Albany AMT'";
color='black'; size=2; position='7'; output;
format Price_A dollar5.2;
text=new_Price_A; style="'Albany AMT'";
color='black'; size=2; position='4'; output;
if ocean='Y' then do;
text=new_Difference; position='6'; output;
function='move';
flag=1;
end;
else if flag=1 then do;
function='draw'; size=2; output;
flag=0;
end;
output;
run;
proc contents data=stlabel;
run;
proc format;
picture Difference_
low - -0.01 = 'negative'
0.00 = 'parity'
0.01 -high = 'positive'
;
run;
proc contents data=response;
pattern1 color=green;
pattern2 color=yellow;
pattern3 color= red;
title 'PRODUCT A V/S PRODUCT B';
proc gmap
data=response
map=maps.us
all;
id STATECODE;
format Difference Difference_.;
choro Difference / discrete annotate=stlabel ;
run;
quit;
enter image description here
[ad_2]
لینک منبع