goptions reset=all target=pscolor ftext=swissb
         gunit=pct htext=2.5
         rotate=landscape ctext=black;


%let headlclr=red;     /* color of the arrowhead outline */
%let headbord=2;       /* thickness of the arrowhead outline in pixels*/
%let headwid=.03;      /* scaling factor for calculating the width of the
                          arrowhead based on the X data range */
%let headfclr=yellow;  /* color of the interior of the arrow head */
%let headlen=.05;      /* scaling factor for calculating the length of the
                          arrowhead based on the Y data range */
%let tailclr=blue;     /* color of the arrow tail */
%let tailsize=8;       /* thickness of the arrow tail in pixels */
%let taillen=.30;      /* scaling factor for calculating the length of the
                          arrow tail based on the Y data range */
%let labelclr=green;   /* color of the arrow label */
%let labelsiz=1.5;     /* size of the arrow label in character cells */
%let labelfnt=centbi;  /* font for the arrow label */


data inds;
input  transno balance date date7.;
if _n_=1 then updown=-1;
else do;
if balance ge lag(balance) then updown=1;
if balance lt lag(balance) then updown=-1;
end;
cards;
1  200 05mar95
2  433 14mar95
3  375 13apr95
4  500 18apr95
5  600 26jul95
6  750 17aug95
7  850 21sep95
8  456 12oct95
9  300 13dec95
10 550 20dec95
11 299 29dec95
;
run;

proc means min max noprint data=inds;
var transno balance;
output out=xyrange
min=minxvar minyvar
max=maxxvar maxyvar;
run;

data xyrange;
set xyrange;
minxvar=minxvar - (.05 * abs(maxxvar));
maxxvar=maxxvar + (.05 * abs(maxxvar));
minyvar=minyvar - ((2 * &taillen) * abs(maxyvar));
maxyvar=maxyvar + ((2 * &taillen) * abs(maxyvar));
run;

data preanno;
if _n_=1 then set xyrange;
set inds;
run;

data anno;
set preanno;
length function color style $ 8 text $ 10 position $1;
retain xsys ysys '2';

**** draw the filled arrowhead ****;
function='move';
when='a';
x=transno;
y=balance;
output;

function='poly';
x=transno-(&headwid * abs(maxxvar));
y=balance+((&headlen * abs(maxyvar))) * updown;
color="&headfclr";
style='msolid';
output;

function='polycont';
x=transno+(&headwid * abs(maxxvar));
y=balance+((&headlen * abs(maxyvar)) * updown);
output;

function='polycont';
x=transno;
y=balance;
output;

**** draw the arrowhead outline ****;
function='move';
x=transno;
y=balance;
output;

function='draw';
x=transno-(&headwid * abs(maxxvar));
y=balance+((&headlen * abs(maxyvar)) * updown);
color="&headlclr";
size=&headbord;
output;

function='draw';
x=transno+(&headwid * abs(maxxvar));
y=balance+((&headlen * abs(maxyvar)) *updown);
output;

function='draw';
x=transno;
y=balance;
output;

**** draw the arrow tail ****;
function='move';
x=transno;
y=balance;
output;

function='draw';
x=transno;
y=balance+(&taillen * updown * (abs(maxyvar)));
color="&tailclr";
size=&tailsize;
when='b';
output;

**** place date above or below the arrow ****;
function='label';
when='a';
x=transno;
y=balance+(&taillen * abs(maxyvar)* updown);
text=put(date,date7.);
size=&labelsiz;
style="&labelfnt";
color="&labelclr";
if updown=1 then position='2';
else position='8';
output;
run;


title1 height=4 '1995 Account Summary';
proc gplot data=preanno anno=anno;
format balance comma5.;
plot balance * transno=1
     maxyvar * maxxvar=2
     minyvar * minxvar=2 / overlay
                           haxis=axis1
                           vaxis=axis2;
axis1 label=('Transaction Number') minor=none;
axis2 label=(angle=90 rotate=0 'Account Balance (in dollars)');
symbol1 interpol=join value=dot color=green width=3 height=3;
symbol2 interpol=none value=none;
run;
quit;