Sample 24924: Create a KAGI plot
/*****************************************************************/
/* The purpose of this program is to simulate a KAGI type chart. */
/* The variations in line thickness and line color have meaning. */
/* Typically used to follow stock prices, this example generates */
/* a thicker green line when the price rises and a narrower red */
/* line when the price falls. */
/*****************************************************************/
/* Reset global statements */
goptions reset=all;
/* Create sample data set ONE */
data one;
input date date9. open close;
datalines;
05aug2002 5 3
06aug2002 3 7
07aug2002 7 9
08aug2002 9 2
09aug2002 2 5
12aug2002 5 8
13aug2002 8 2
14aug2002 2 2
;
/* Create data set ANNO1, */
/* generate red vertical lines connecting */
/* OPEN and CLOSE values for each DATE */
data anno1;
set one;
length function color $8;
function='move'; xsys='2'; ysys='2'; x=date; y=open; output;
function='draw'; xsys='2'; ysys='2'; x=date; y=close;
color='red'; output;
run;
/* Create data set ANNO2, */
/* Conditionally generate the thicker green lines, */
/* Generate the horizontal lines */
data anno2;
set one;
retain tempopen tempclos tempdate topen2 tclos2;
length function color flag $8;
if close < open then flag='down';
if close > open then flag='up';
if close = open then flag='even';
tempopen=lag(open);
tempclos=lag(close);
tempdate=lag(date);
topen2=lag2(open);
tclos2=lag2(close);
if (lag1(flag)='down' and flag='up' and _n_^=1) then do;
if tempopen < close then do;
function='move'; xsys='2'; ysys='2'; x=date; y=tempopen; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=close;
color='green'; when='a'; size=5; output;
end;
function='move'; xsys='2'; ysys='2'; x=tempdate; y=tempclos; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=open;
color='red'; when='a'; size=1; output;
end;
if (lag1(flag)='up' and flag='up' and _n_^=1) then do;
function='move'; xsys='2'; ysys='2'; x=date; y=tempclos; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=close;
color='green'; when='a'; size=5; output;
if topen2 > open then color='red'; else color='green';
if color='red' then size=1; else size=5;
function='move'; xsys='2'; ysys='2'; x=tempdate; y=tempclos; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=open; when='a'; output;
end;
if (lag1(flag)='up' and flag='down' and _n_^=1) then do;
function='move'; xsys='2'; ysys='2'; x=date; y=tempopen; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=open;
color='green'; when='a'; size=5; output;
function='move'; xsys='2'; ysys='2'; x=tempdate; y=tempclos; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=open;
color='green'; when='a'; size=5; output;
end;
if (flag='even' and _n_^=1) then do;
if topen2 > open then color='red'; else color='green';
if color='red' then size=1; else size=5;
function='move'; xsys='2'; ysys='2'; x=tempdate; y=tempclos; output;
function='draw'; xsys='2'; ysys='2'; hsys='4'; x=date; y=open; when='a'; output;
end;
run;
/* Specify SYMBOL statement, */
/* suppress value and line */
symbol1 v=none i=none c=black r=2;
/* Specify AXIS1 statement assigned to X-axis */
axis1 order=('05aug2002'd to '14aug2002'd by weekday)
offset=(2,2)pct minor=none;
/* Specify TITLE statement */
title1 h=2.5 'KAGI Plot';
/* Generate GPLOT */
proc gplot data=one annotate=anno1;
plot open*date close*date /overlay haxis=axis1 annotate=anno2;
format date mmddyy5.;
run;
quit;

This sample program uses Annotate to simulate a KAGI type chart.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Plots ==> Special Plot types
|
| Date Modified: | 2005-08-31 03:03:18 |
| Date Created: | 2004-11-11 11:08:01 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |