%let name=fm_92;

/*

In this example, I try to use SAS/Graph to do some animated bubble plots,
similar to what JMP does.

Here's where I got my data:

Data from the JMP webcast, where they plotted sales*advertising, and
sized the bubbles by payroll, and animated over time (Wes Rehm)...

   \\L9880\public\jmp\fm_extract_to_sas_visual_bi.sas7bdat (ok to use)

*/

libname mydata '.';

%let dataset=fm_extract_to_sas_visual_bi;
%let yvar=operating_profit;
%let xvar=operating_expense;
%let colorvar=region_name;
%let colorvar=organization_name;


proc sql;
 create table plotdata as
 select * 
 from mydata.&dataset
 where (date ne .)
 order by date;
quit; run;

proc sql;
 create table annodate as
 select unique date
 from plotdata
 where (date ne .)
 order by date;
quit; run;

data plotdata; set plotdata;
format date monyy7.;
format &yvar dollar12.0;
format &xvar dollar12.0;
run;


data annodate; set annodate;
xsys='1'; ysys='1'; when='a';
x=83; y=89; 
function='label'; position='5'; style=''; color='gray'; 
text=put(date,monyy7.); output;
run;


/**  Script out the HTML file that will display the GIF animation. **/
data _null_;
   file "&name..htm";
   put '<HTML>';
   put '<title>FM Data Animation (SAS/Graph gifanim) </title>';
   put '<BODY>';
   put '<BLOCKQUOTE>';
   put '<P><img src="' "&name..gif" '" title="FM Data Animation (SAS/Graph gifanim) " ';
   put '</BLOCKQUOTE>';
   put '</BODY>';
   put '</HTML>';

filename gifname "&name..gif";

/**  Set the GOPTIONs necessary for the animation    **/
goption reset  
  dev=gifanim  
  gsfname=gifname  
  gsfmode=replace      /* For the first graph, gsfmode=replace */
  disposal=background  /* none, background, previous, or unspecified */
  userinput            /* allow user input during animation, if supported by browser */
  delay=30             /* .40 seconds between images */
  iteration=1          /* loop through animation 1 time (0=infinite) */
;

goptions xpixels=900 ypixels=600;
options nogstyle;
/* nogstyle is a v9.2 option - delete it for this code to work at v9.1.3 */

goptions noborder;
goptions cback=white;
goptions gunit=pct htitle=4 htext=3 ftitle="albany amt/bold" ftext="albany amt";

options nobyline;
title "Financial Management (FM) Results";

/*
In v9.2 fonts are only "registered" at the time of the sas install,
and since I'm running "sdssas", which wasn't really installed on my
pc, but the install was run on another machine on the network,
that didn't have wingding fonts installed, I have to do a "fontreg"
so that I can use the wingding fonts, etc...
*/
proc fontreg;
fontpath 'C:\WINNT\FONTS';
run;

/*
symbol value=dot height=5.0 repeat=1000;
*/
symbol font="wingdings 2" v='98'x h=4.5 repeat=1000;



axis1 color=graycc value=(color=gray) label=(color=black) order=(-50000000 to 150000000 by 50000000) minor=none offset=(0,0);
axis2 color=graycc value=(color=gray) label=(color=black) order=(0 to 75000000 by 25000000) minor=none offset=(0,0);

legend1 position=(right middle) across=1 label=none repeat=1;
/* repeat= is a new v9.2 feature ... delete it if you want this code to work in v9.1.3 */
 
proc gplot data=plotdata;
by date;
plot &yvar*&xvar=&colorvar /
 anno=annodate
 vaxis=axis1 haxis=axis2
 vref=(0 50000000 100000000 150000000) cvref=(black graycc graycc graycc)
 autohref chref=graycc
 legend=legend1
 noframe
 ;
run;

/*
Now, write out the end of the animatd gif trailer - otherwise it won't play in some gif players.

Internet Explorer will sometimes display animated GIFs that do not have it,
but the W3C spec says it is required.  Office 2002 and 2003 apparently do not
recognize the files unless they include this trailer.
*/
data _null_;
   file gifname recfm=n mod;
   put '3B'x;
run;

quit;
