48 %local dsid grouptype xvalues xvalues2;
51 %let dsid=%sysfunc(open(&data));
52 %
if &dsid=0 %then %
do;
53 %put ERROR: boxplot: Data
set &data does not exist;
57 %
if "&x"=
"" %then %
do;
58 %put ERROR: boxplot: X variable not specified;
59 %let dsid=%sysfunc(close(&dsid));
63 %
if %sysfunc(varnum(&dsid,&x))=0 %then %
do;
64 %put ERROR: boxplot: Variable &x does not exist in data
set &data ;
65 %let dsid=%sysfunc(close(&dsid));
70 %
if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&x)))) NE N %then %do;
71 %put ERROR: boxplot: Variable &x in data set &data must be numeric;
72 %let dsid=%sysfunc(close(&dsid));
77 select distinct &x into :xvalues separated by '" "' from &data;
78 select distinct &x into :xvalues2 separated by ' ' from &data;
81 %if "&y"="" %then %do;
82 %put ERROR: boxplot: Y variable not specified;
83 %let dsid=%sysfunc(close(&dsid));
87 %if %sysfunc(varnum(&dsid,&y))=0 %then %do;
88 %put ERROR: boxplot: Variable &y does not exist in data set &data ;
89 %let dsid=%sysfunc(close(&dsid));
93 %if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&y)))) NE N %then %do;
94 %put ERROR: boxplot: Variable &y in data set &data must be numeric;
95 %let dsid=%sysfunc(close(&dsid));
99 %if "&group"="" %then %do;
100 %put ERROR: boxplot: Group variable must be specified;
101 %let dsid=%sysfunc(close(&dsid));
105 %if %sysfunc(varnum(&dsid,&group))=0 %then %do;
106 %put ERROR: boxplot: Variable &group does not exist in data set &data ;
107 %let dsid=%sysfunc(close(&dsid));
111 %let grouptype=%sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&group))));
114 select count(distinct &group) into :count from &data;
115 select min(&group) into :lower from &data;
117 %if &lower=. %then %do;
118 %put ERROR: boxplot: Missing values in group variable are not allowed;
120 proc sql noprint; drop table &d_1; quit;
122 %if &count NE 2 %then %do;
123 %put ERROR: boxplot: Variable &group must have exactly two values;
127 %let dsid=%sysfunc(close(&dsid));
135 create table &d_1 as select distinct &x from &data;
141 if _n_>1 then output;
144 %local xdiff1 xdiff2 xmin xmax misscount;
146 select mean(&x), min(&x) into :xdiff1, :xdiff2 from &d_1;
147 select min(&x), max(&x) into :xmin, :xmax from &data;
149 select count(*) into :misscount from &data where &x is missing;
151 %if &xdiff1=. %then %do;
152 %put ERROR: boxplot: x variable must have at least two values;
154 proc sql noprint; drop table &d_1; quit;
156 %if &misscount>0 %then %do;
157 %put ERROR: boxplot: Missing values in x variable are not allowed;
159 proc sql noprint; drop table &d_1; quit;
162 %let xmin=%sysevalf(&xmin-&xdiff1);
163 %let xmax=%sysevalf(&xmax+&xdiff1);
166 %if &xdiff1 ne &xdiff2 %then %do;
167 %put ERROR: boxplot: Values of x variable are not equidistant;
169 proc sql noprint; drop table &d_1; quit;
175 SET &data (KEEP=&x &y &group);
176 IF &group = %if &grouptype=N %then &lower; %else "&lower"; THEN DO;
177 &x = &x - 0.11*&xdiff1;
180 &x = &x + 0.11*&xdiff1;
183 %let d_plot=&syslast;
186 GOPTIONS FTEXT="Helvetica" HTEXT=12pt hsize=16cm vsize=16cm;
187 SYMBOL1 WIDTH = 3 BWIDTH = 3 COLOR = gray LINE = 2 VALUE = none INTERPOL = BOXJT00 MODE = include;
188 SYMBOL2 WIDTH = 3 BWIDTH = 3 COLOR = black LINE = 1 VALUE = none INTERPOL = BOXJT00 MODE = include;
189 AXIS1 LABEL=(ANGLE=90) MINOR=none;
190 AXIS2 ORDER=(&xmin &xvalues2 &xmax) VALUE=(" " "&xvalues" " ") MINOR=none;
193 ODS PDF FILE="&report";
195 PROC GPLOT DATA=&d_plot;
196 PLOT &y * &x = &group / VAXIS=Axis1 HAXIS=Axis2 LEGEND=Legend1 NOFRAME;