Data visualization with SAS programming

Proc Gmap

Reply
Occasional Contributor
Posts: 14

Proc Gmap

I would like to label each pie  with their corresponding info.  pass%/fail%/withhold%. how do i get the labels for each pie?

1.png

Occasional Contributor
Posts: 14

Re: Proc Gmap

Code used is from Robs link:/*Cleared denotes pass Returned denotes fail outstanding denotes withhold)

/* Create dataset containing the dots */

data dots;

length html $500;

length function color $ 8;

set my_data_final;

mp=deposited/value;

fp=returned/value;

op=outstanding/value;

html=

'title='||quote(

  'State: '||trim(left(fipnamel(Us_state)))||'0D'x||

  'Cleared   : '||put(Deposited,comma10.)||    '  ('||put(mp,percent6.0)||')'||'0D'x||

  'Returned: '||put(Returned,comma10.)||'  ('||put(fp,percent6.0)||')'||'0D'x||

    'Outstanding: '||put(Outstanding,comma10.)||'  ('||put(op,percent6.0)||')'||'0D'x||

  '------------------------------------------- '||'0D'x||

  'Total Checks: '||put(value,comma10.)

  )||

' href='||quote('#'||trim(left(US_State)));

xsys='2'; ysys='2'; hsys='3';

when='A';  function='PIE'; line=0;

style='SOLID'; percent=Deposited/value*100;

rotate=percent*360/100;

color="&cdeposited";  if ocean~='Y' then output;

percent=Returned/value*100; rotate=percent*360/100;

color="&creturned"; if ocean~='Y' then output;

percent=Outstanding/value*100; rotate=percent*360/100;

color="&cOutstanding"; if ocean~='Y' then output;

line=0; style='pempty'; color='gray33';

angle=0.0; rotate=360.0;

if ocean~='Y' then output;

color="&coutstanding"; if ocean~='Y' then output;

line=0; style='pempty'; color='orange';

angle=0.0; rotate=360.0;

run;

data legend;

length function text color $8;

xsys='1'; ysys='1'; hsys='1';

when='A';

color="&cDeposited"; percent=outside; line=0; angle=0.0; rotate=360.0;

function='PIE  '; size=1.5;

style='SOLID'; x=.17; y=.23; output;

color="&cReturned"; percent=outside; x=.17; y=.20; output;

color="black";

color="&cOutstanding"; percent=outside; x=.17; y=.18; output;

color="black";

function='LABEL'; size=2; position='2';

text='Deposited'; x=.19; y=.235; output;

text='Returned  '; x=.19; y=.205; output;

  text='Outstanding  '; x=.19; y=.205; output;

run;

data dots;

set dots legend;

run;

/* This is something I added in 2007 - it creates a bunch of tables below the map

   (one table for each state) with html anchor tags, so I can "drilldown" to them.

*/

%macro do_table(statecode);

%local data_name statecode;

proc sql noprint;

create table foo as select * from datalib.smm where st="&statecode";

select unique state into :statename from foo;

quit; run;

data foo; set foo;

Deposited=Deposited*1000;

Returned=Returned*1000;

Outstanding=Outstanding*1000;

Deposited_percent=Deposited/(Deposited+Returned+Outstanding);

Returned_percent=Returned/(Deposited+Returned+Outstanding);

Outstanding_percent=Outstanding/(Deposited+Returned+Outstanding);

  run;

options nocenter;

ods html anchor="&statecode";

title1 "Statewise Status Counts in U.S. ... " f="albany amt/bold" "&statename";

goptions xpixels=500 ypixels=200 htitle=8pct htext=6pct;

symbol1 c=&cdeposited i=join v=dot;

symbol2 c=&creturned  i=join v=dot;

symbol2 c=&cOutstanding  i=join v=dot;

axis1 label=none minor=none order=(0 to 1 by .25) offset=(0,0);

axis2 label=none minor=none offset=(0,0);

goptions noborder;

proc gplot data=foo/anno=dots;

format Deposited_percent Returned_percent Outstanding_percent percent7.0;

title2 c=&CDeposited "----  Cleared     " c=&CReturned "---- Return" c=&COutstanding "---- Outstanding";

footnote;

plot Deposited_percent*year=1 Returned_percent*year=2 Outstanding_percent*year=2 / anno=dots overlay

  vzero noframe

  vaxis=axis1

  haxis=axis2

  vref=.5 cvref=graycc lvref=3

  des='' name="plt.&statecode";

run;

title2;

proc print data=foo noobs label;

format  Deposited  Returned Outstanding comma10.;

format Deposited_percent Returned_percent Outstanding_percent percent7.0;

label Deposited='Deposited';

label Returned='Returned';

  label Outstanding='Outstanding';

label Deposited_percent='Deposited %';

label Returned_percent='Returned %';

  label Outstanding_percent='Outstanding %';

var year Deposited Returned Outstanding Deposited_percent Returned_percent Outstanding_percent;

run;

%mend do_table;

options ls=80 ps=1000 nocenter nodate;

goptions reset=global gunit=pct rotate=landscape

gunit=pct htitle=5.0 htext=3.0 ftitle="albany amt/bold" ftext="albany amt"

cback=white ctext=black colors=(black);

goptions device=png;

ODS LISTING CLOSE;

ODS HTML path=odsout body="&name..htm" (title="Pie-chart Map")

options(pagebreak='no') style=minimal;

goptions noborder;

title1 ls=1.5 'Statewise Status Counts in U.S.';

/* Plot the dots on a US map */

pattern1 v=solid c=white;

goptions border;

proc gmap data=maps.us map=maps.us (where=(state ^= stfips('PR'))) anno=dots ;

id state;

choro state /levels=1 legend=legend

coutline=gray33

des='' name="&name";

run;

quit;

ODS HTML CLOSE;

ODS LISTING;

Grand Advisor
Posts: 10,223

Re: Proc Gmap

The basic answer is add text to the annotate data set.

Figure an offset distance from the center of your pie charts, use some trig to get 3 XY pairs at points around the chart, and assign text.

What is the physical size of the display you expect this to be used? You are going to be severely challenged in parts of New England, Maryland and Delaware. You may have to have the numbers quite a distance away and draw lines to the charts. If so, expect lots of trial and error.

SAS Employee
Posts: 967

Re: Proc Gmap

You might try using the 'piexy' annotate function to calculate the x/y position for annotated label text to place around the pies. I don't think I've ever used this technique, and you're likely to run into several 'gotchas' such as overlapping text labels, and determining a 'position' (left/right/center/etc) for the label, etc. This is going to be a difficult endeavor, and the results might not justify the effort.

SAS/GRAPH(R) 9.4: Reference, Second Edition

Perhaps there is a different/better alternative to visually analyze this data(?)

Occasional Contributor
Posts: 14

Re: Proc Gmap

Thanks. Will try.

Ask a Question
Discussion stats
  • 4 replies
  • 473 views
  • 0 likes
  • 3 in conversation