Sample 35040: Monthly Stock Price and Volume Graph
This is a plot of the daily stock price, technical indicators, and share volume for a company. This graph is built using a two-cell layout lattice with the Graph Template Language (GTL).
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses the Graph Template Language (GTL) to produce two graphs on a page. One graph contains a band plot overlay and the second graph contains a needle plot with a line plot overlay.
proc sort data=sashelp.stocks out=stocks;
by date;
run;
data splitIBM;
length split $3;
set stocks(where=(stock="IBM"));
label volume='(millions)';
volume=volume/1000000;
if date < '01MAY97'd then do;
open = open / 4;
close = close/4;
high=high / 4;
low=low/4;
end;
else if date ='01MAY97'd then do;
open = open / 4;
close = close/2; /*Anomaly in data */
high=high / 4;
low=low/2; /*Anomaly in data */
split="2/1";
freq=1;
end;
else if date <'03MAY99'd then do;
open = open / 2;
close = close/2;
high=high / 2;
low=low/2;
end;
else if date ='03MAY99'd then do;
open = open / 2;
high=high / 2;
split="2/1";
freq=1;
end;
run;
data moveavg(drop=move25index move50index);
set splitIBM;
retain closehigh prevvolume;
array move25[25] _temporary_;
array move50[50] _temporary_;
array vmove25[25] _temporary_;
format close high low avg25 avg50 vavg dollar8.0;
move25index=mod(_n_,25);
move50index=mod(_n_,50);
vmove25index=mod(_n_,25);
move25index =ifn(move25index,move25index,25);
move50index =ifn(move50index,move50index,50);
vmove25index =ifn(vmove25index,vmove25index,25);
move25[move25index]=close;
move50[move50index]=close;
vmove25[vmove25index]=volume;
if _n_ ge 25 then do;
avg25=mean(of move25[*]);
vavg=mean(of vmove25[*]);
bolupper= avg25 + (2*std(of move25[*]));
bollower= avg25 + (-2*std(of move25[*]));
end;
if _n_ ge 50 then avg50=mean(of move50[*]);
if _n_ gt 1 then do;
if close gt closehigh then do;
cindex = 1;
closehigh = close;
end;
else do;
cindex = 2;
closehigh=closehigh;
end;
if volume gt prevvolume then
vindex = 1;
else
vindex = 2;
prevvolume=volume;
end;
else do;
closehigh=close;
prevvolume=volume;
cindex=1;
vindex=1;
end;
run;
proc template;
define style styles.Stock;
parent = Styles.default;
class color_list from color_list
"Colors used in the default style" /
'bgA' = cxF0F0FF;
class GraphColors from graphcolors
"Abstract colors used in graph styles" /
'gconfidence' = cxF0D0F0 /* cxF0F080 */
'ggrid' = cxE0E0FF
'gcdata1' = cx6060D9;
Style GraphFonts "Fonts used in graph styles" /
"GraphAnnoFont" = (", ", 10pt)
"GraphTitleFont" = (", ", 11pt, bold)
"GraphFootnoteFont" = (", ", 10pt)
"GraphLabelFont" = (", ", 10pt)
"GraphValueFont" = (", ", 9pt)
"GraphUnicodeFont" = ("", 9pt)
"GraphDataFont" = (", ", 9pt)
;
end;
run;
proc template;
define statgraph stockplot;
begingraph / designwidth=600px designheight=400px;
entrytitle "Monthly Stock Price";
layout lattice / columns=1 columndatarange=union rowweights=(0.7 0.3);
columnaxes;
columnaxis / offsetmin=0.02 griddisplay=on;
endcolumnaxes;
layout overlay / cycleattrs=true yaxisopts=(griddisplay=on label=" "
display=(line) displaysecondary=all);
bandplot x=date limitupper=bolupper limitlower=bollower / datatransparency=0.5
display=(fill outline) name="boll" outlineattrs=(pattern=solid)
fillattrs=graphconfidence legendlabel="Bollinger Bands(25,2)";
vectorplot xorigin=date y=low yorigin=high x=date / arrowheads=false group=cindex
index=cindex lineattrs=(pattern=solid thickness=1px) shaftprotected=true;
scatterplot x=date y=close / group=cindex index=cindex markerattrs=(symbol=plus size=2);
scatterplot x=date y=close / freq=freq markerattrs=(symbol=starfilled size=7)
datalabel=split name="split" legendlabel="Split";
seriesplot x=date y=avg25 / lineattrs=(thickness=2px) legendlabel="SMA(25)" name="d25";
seriesplot x=date y=avg50 / lineattrs=(pattern=solid thickness=2px)
legendlabel="SMA(50)" name="d50";
discretelegend "boll" "d25" "d50" "split" / across=1 border=on valign=top halign=left
location=inside opaque=true;
endlayout;
layout overlay / yaxisopts=(griddisplay=on display=(line) displaysecondary=all)
cycleattrs=true xaxisopts=(griddisplay=on);
needleplot x=date y=volume / name="vol" legendlabel="Volume"
lineattrs=(pattern=solid thickness=1px);
seriesplot x=date y=vavg / name="vavg" legendlabel="SMA(25)"
lineattrs=(pattern=solid thickness=2px);
discretelegend "vol" "vavg" / across=1 location=inside border=on halign=left
valign=top opaque=true;
endlayout;
endlayout;
endgraph;
end;
run;
ods listing close;
ods html file="StockPlot.html" path='.' style=Stock image_dpi=100;
ods graphics / reset imagename='GTLHandout_StockPlot' imagefmt=gif;
proc sgrender data=moveavg template=stockplot;
run;
ods html close;
ods listing;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses the Graph Template Language (GTL) to produce two graphs on a page. One graph contains a band plot overlay and the second graph contains a needle plot with a line plot overlay.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SGRENDER Query and Reporting ==> Creating Reports ==> Graphical ==> Financial Industry Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Template Language (GTL)
|
Date Modified: | 2009-03-19 09:23:00 |
Date Created: | 2009-03-05 13:40:25 |
Operating System and Release Information
SAS System | SAS/GRAPH | Linux | 9.2 TS1M0 | |
HP-UX IPF | 9.2 TS1M0 | |
64-bit Enabled Solaris | 9.2 TS1M0 | |
64-bit Enabled HP-UX | 9.2 TS1M0 | |
64-bit Enabled AIX | 9.2 TS1M0 | |
Windows Vista | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
z/OS | 9.2 TS1M0 | |
Linux for x64 | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 TS1M0 | |
Solaris for x64 | 9.2 TS1M0 | |