Thursday, April 8, 2010

Proc Gplot


*************************************************************************
Proc Gplot statement including Annotation
**outputs to CGM file
**specified Symbol, Axis, and Legend options
**uses Annotate option to add "N=" with number of observation in statistic
************************************************************************;


proc means data=dataset noprint;
by Time;
var Concentration;
output out=graphdata
n=N mean=Mean std=Std min=Min median=Median max=Max cv=CV;
run;
*the original "dataset" is set up with variables for subject, time, and concentration;

filename outplot 'Z:\SAS\Gplot\MeanGraph.cgm';
goptions reset=ALL
gunit=pct
ftext=hwcgm001
ftitle=hwcgm009
htitle=2
htext=2
noborder
maxcolors=255
dev=cgmof97l
rotate=LANDSCAPE
gsfmode=replace
gsfname=outplot;


symbol1 value=diamond i=j color=green h=2.5;
symbol2 value=diamond i=j color=red h=2.5;
symbol3 value=square i=j color=blue h=2.5;
symbol4 value=square i=j color=orange h=2.5;


legend1 down=4 position=(top right inside) frame shape=symbol(7,1.5) mode=protect label=none;

axis1 label=(a=90 height=2.5 color=black "Mean Statistic");
axis2 order=(0 to 30 by 5) label=(height=2.5 color=black "Time (hr)");


data annoplot;
length color function $8;
retain color 'black' function 'label' xsys ysys '2' hsys '1' size 2.5; *set up the coordinates ;
set graphdata;
where time=24;
*this is the last time point in the dataset so will use this y-value;

x=25;
*set up x value at one point after the last value;

y=mean;
text2=put(n,$3.);
*make the N value character;

text=compress('N='||text2);
*put together the character value with the "N=" string;

position='6';
*puts the string to the right ;

run;

proc gplot data=graphdata;
plot mean*time=group/
vaxis=axis1
haxis=axis2
legend=legend1
anno=annoplot;
run;
quit;


*For Further examples, see:
1. SAS examples
2. Robert Allison's SAS Graph Examples

No comments:

Post a Comment