/* Input DATA step. */
data psitest(drop=minpsi maxpsi days)
summary(keep=maxpsi vendor days);
input @1 vendor $ @3 installd date7. @11 removed date7.
@19 minpsi @23 maxpsi;
format installd removed date date7.;
length psicolor pattern $8;
/* Assign sequential test number and calculate test */
/* duration. */
test=_n_;
days=intck('day',installd,removed);
output summary;
/* Create macro variable containing first test date. */
if _n_=1 then call symput('stdate',put(installd,date7.));
/* Assign color and pattern values and create macro variables. */
if vendor='A' then pattern='m1n45';
else if vendor='B' then pattern='m1x45';
else if vendor='C' then pattern='m1n135';
if (maxpsi lt 200) then psicolor='red';
else if ( 200 le maxpsi lt 300) then psicolor='yellow';
else if (maxpsi ge 300) then psicolor='green';
call symput('pat'||left(test),pattern);
call symput('color'||left(test),psicolor);
/* Define polygon. */
date=installd;
psi=minpsi; output psitest; /* Define Vertex 1 */
psi=maxpsi; output psitest; /* Define Vertex 2 */
date=removed; output psitest; /* Define Vertex 3 */
psi=minpsi; output psitest; /* Define Vertex 4 */
date=installd; output psitest;/* Define Vertex 5 */
cards;
A 01jan95 07jan95 95 195
B 07jan95 20jan95 50 435
C 20jan95 25jan95 100 210
A 25jan95 02feb95 135 265
B 02feb95 15feb95 175 425
C 15feb95 23feb95 75 205
A 23feb95 28feb95 125 360
B 28feb95 10mar95 85 375
C 10mar95 17mar95 125 195
A 17mar95 20mar95 105 210
B 20mar95 25mar95 220 440
C 25mar95 01apr95 45 175
;
run;
________________________________________________________________________
/* Compile Annotate macros. */
%annomac;
/* Create Annotate data set. */
data anno;
set psitest end=eof;
by test;
/* Set lengths and type for Annotate variables. */
%dclanno;
length text $10;
/* If first observation in the data set, label the first */
/* date on the horizontal axis. All annotated text uses the */
/* Helvetica-Bold PostScript hardware font (HWPSL011). */
if _n_=1 then do;
%system(2,1,3);
%move("&stdate"d,0);
%cntl2txt;
%system(2,9,3);
%label("&stdate"d,-2.5,
upcase(trim(left("&stdate"))),
black,45,0,2,hwpsl011,4);
end;
/* If last observation for each polygon, label the removal */
/* date on the horizontal axis. */
if last.test then do;
%system(2,1,3);
%move(removed,0);
%cntl2txt;
%system(2,9,3);
%label(removed,-2.5,
trim(left(put(removed,date7.))),
black,45,0,2,hwpsl011,4);
end;
if eof then do;
/* Create macro variables containing the total number of */
/* samples and the last test date. */
call symput('total',test);
call symput('enddate',put(removed,date7.));
/* Draw PSI legend. */
%system(3,3,3);
%label(20,4,'MAX PSI:',black,0,0,2,hwpsl011,<);
%bar(25,2,35,6,red,0,solid);
%cntl2txt;
%system(9,3,3);
%label(2,4,'0 - 200',black,0,0,2,hwpsl011,>);
%system(3,3,3);
%bar(50,2,60,6,yellow,0,solid);
%cntl2txt;
%system(9,3,3);
%label(2,4,'200 - 300',black,0,0,2,hwpsl011,>);
%system(3,3,3);
%bar(75,2,85,6,green,0,solid);
%cntl2txt;
%system(9,3,3);
%label(2,4,'> 300',black,0,0,2,hwpsl011,>);
/* Draw VENDOR legend. */
%system(3,3,3);
%label(20,10,'VENDOR:',black,0,0,2,hwpsl011,<);
%bar(25,8,35,12,*,0,R1);
%cntl2txt;
%system(9,3,3);
%label(2,10,'A',*,0,0,2,hwpsl011,>);
%system(3,3,3);
%bar(50,8,60,12,*,0,X1);
%cntl2txt;
%system(9,3,3);
%label(2,10,'B',*,0,0,2,hwpsl011,>);
%system(3,3,3);
%bar(75,8,85,12,*,0,L1);
%cntl2txt;
%system(9,3,3);
%label(2,10,'C',*,0,0,2,hwpsl011,>);
end;
run;
________________________________________________________________________
/* Define macro to specify solid-filled map/plot */
/* interpolations. */
%macro barcolor;
%do i=1 %to &total;
SYMBOL&i INTERPOL=MSOLID COLOR=&&color&i VALUE=NONE;
%end;
%mend;
/* Define macro to specify patterned map/plot interpolations. */
%macro barpatrn;
%do i=1 %to &total;
%let j=%eval(&i+&total);
SYMBOL&j INTERPOL=&&pat&i COLOR=BLACK VALUE=NONE;
%end;
%mend;
/* Invoke the macros. */
%barcolor;
%barpatrn;
________________________________________________________________________
/* Specify graphics options. */
goptions device=pscolor ftext=hwpsl011
gunit=pct htext=2.5 vsize=5 in
nodisplay;
/* Produce the first graph. */
proc gplot data=psitest;
title1 height=4 'Pressure Test for Valve #3162';
axis1 order="&stdate"d to "&enddate"d by day
minor=none offset=(2,2) value=none label=none;
axis2 offset=(0,0)
label=(angle=90 rotate=0 "Pressure (psi)")
origin=(10,);
axis3 offset=(0,0) label=none value=(justify=l);
/* Plot solid-colored polygons. */
plot psi*date=test / haxis=axis1
vaxis=axis2
/* Suppress the legend on the plot. */
nolegend
/* Draw a frame around the axis area. */
frame
/* Start the vertical axis with a value of 0. */
vzero
/* Draw reference lines. */
vref=200 300
/* Specify the Annotate data set to apply. */
anno=anno;
/* Plot patterned polygons. */
plot2 psi*date=test / haxis=axis1
vaxis=axis3
nolegend
vzero;
/* Add FOOTNOTE to provide blank space at bottom of graph, */
/* with a height of 18% of the graphics output area. */
footnote1 height=18 ' ';
run;
quit;
________________________________________________________________________
/* Sort the SUMMARY data set. */
proc sort data=summary;
by vendor;
/* Calculate average test duration and maximum pressure */
/* for each vendor. */
proc means data=summary mean noprint;
var days maxpsi;
by vendor;
output out=vstats mean=avedays avemax;
run;
________________________________________________________________________
/* Prepare data for summary chart. */
data vstats(keep=i avemax vendor tot)
fmtdata(keep=fmtname start label type);
set vstats end=eof;
length psicolor $8 label $16;
/* Assign counter variable. */
count=_n_;
/* Round the average number of days to the nearest 1/2 day. */
tot=round(avedays,.5);
/* Create variables to use with CNTLIN= data set */
/* with PROC FORMAT. */
fmtname='vfmt'; /* Identifies the format name. */
type='c'; /* Format type will be Character. */
start=vendor; /* Variable to be formatted is VENDOR. */
/* Formatted value. */
label=trim(vendor)||': AVE '
||trim(left(put(tot,5.1)))||' DAYS';
output fmtdata;
/* Assign color values and create macro variables. */
if (avemax lt 200) then psicolor='red';
else if ( 200 le avemax lt 300) then psicolor='yellow';
else if (avemax ge 300) then psicolor='green';
call symput('col'||left(count),psicolor);
/* Output multiple observations based on value */
/* of variable TOT. */
do i= 5 to tot by .5;
output vstats;
end;
if eof then do;
/* Create macro variable containing total number of vendors. */
call symput('totv',count);
end;
run;
/* Use the CNTLIN= option with the FORMAT procedure to create */
/* data-dependent formatted values for each VENDOR code. */
proc format cntlin=fmtdata;
run;
/* Reset global graphics options before producing */
/* second chart. */
goptions reset=global;
_________________________________________________________________________
/* Define macro to specify solid bar patterns with */
/* data-dependent color. */
%macro vpats;
%do i=1 %to &totv;
PATTERN&i VALUE=SOLID COLOR=&&col&i;
%end;
%mend;
/* Invoke the VPATS macro. */
%vpats;
_________________________________________________________________________
/* Produce summary chart. */
proc gchart data=vstats;
vbar i / discrete
sumvar=avemax
/* Group the bars by the variable VENDOR. */
group=vendor
/* Remove space between bars. */
space=0 /* Draw reference lines. */
ref=200 300
/* Clip the reference lines behind the bars. */
clipref
/* Suppress bars with 0 response value. */
nozeros /* Modify axes attributes. */
maxis=axis1
raxis=axis2
gaxis=axis3
/* Apply pattern by GROUP value. */
patternid=group
/* Place a frame around the axis area. */
frame;
axis1 value=none label=none offset=(2,2);
axis2 label=(angle=90 rotate=0
'Average Maximum Pressure (psi)')
origin=(15,) offset=(0,0);
axis3 label=none value=(height=2) length=75;
format vendor $vfmt.;
run;
quit;
_________________________________________________________________________
/* Specify graphics options before combining graphs. */
goptions vsize=0 display;
/* Combine graphs together on one page. */
proc greplay nofs igout=work.gseg tc=sashelp.templt;
template v2;
tplay 1:gplot 2:gchart;
run;
quit;