45 %local dsid grouptype xvalues xvalues2;
 
   48 %let dsid=%sysfunc(open(&data));
 
   49 %
if &dsid=0 %then %
do; 
 
   50    %put ERROR: boxplot: Data set &data does not exist; 
 
   54 %
if "&x"=
"" %then %
do;
 
   55    %put ERROR: boxplot: X variable not specified; 
 
   56    %let dsid=%sysfunc(close(&dsid));
 
   60 %
if %sysfunc(varnum(&dsid,&x))=0 %then %
do;
 
   61    %put ERROR: boxplot: Variable &x does not exist in data set &data ; 
 
   62    %let dsid=%sysfunc(close(&dsid));
 
   67 %
if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&x)))) NE N %then %do;
 
   68    %put ERROR: boxplot: Variable &x in data set &data must be numeric; 
 
   69    %let dsid=%sysfunc(close(&dsid));
 
   74    select distinct &x into :xvalues separated by '" "' from &data;
 
   75    select distinct &x into :xvalues2 separated by ' ' from &data;
 
   78 %if "&y"="" %then %do;
 
   79    %put ERROR: boxplot: Y variable not specified; 
 
   80    %let dsid=%sysfunc(close(&dsid));
 
   84 %if %sysfunc(varnum(&dsid,&y))=0 %then %do;
 
   85    %put ERROR: boxplot: Variable &y does not exist in data set &data ; 
 
   86    %let dsid=%sysfunc(close(&dsid));
 
   90 %if %sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&y)))) NE N %then %do;
 
   91    %put ERROR: boxplot: Variable &y in data set &data must be numeric; 
 
   92    %let dsid=%sysfunc(close(&dsid));
 
   96 %if "&group"="" %then %do;
 
   97    %put ERROR: boxplot: Group variable must be specified; 
 
   98    %let dsid=%sysfunc(close(&dsid));
 
  102 %if %sysfunc(varnum(&dsid,&group))=0 %then %do;
 
  103    %put ERROR: boxplot: Variable &group does not exist in data set &data ; 
 
  104    %let dsid=%sysfunc(close(&dsid));
 
  108 %let grouptype=%sysfunc(vartype(&dsid,%sysfunc(varnum(&dsid,&group))));
 
  111    select count(distinct &group) into :count from &data;
 
  112    select min(&group) into :lower from &data;
 
  114 %if &lower=. %then %do; 
 
  115    %put ERROR: boxplot: Missing values in group variable are not allowed; 
 
  117    %*** This is code not covered by any test case and left intentionally here to ***;
 
  118    %*** demonstrate the functionality of the test coverage                       ***;
 
  119    proc sql noprint; drop table &d_1; quit;
 
  121 %if &count NE 2 %then %do;
 
  122    %put ERROR: boxplot: Variable &group must have exactly two values; 
 
  126 %let dsid=%sysfunc(close(&dsid));
 
  134    create table &d_1 as select distinct &x from &data;
 
  140    if _n_>1 then output; 
 
  143 %local xdiff1 xdiff2 xmin xmax misscount;
 
  145    select mean(&x), min(&x) into :xdiff1, :xdiff2 from &d_1;
 
  146    select min(&x), max(&x) into :xmin, :xmax from &data;
 
  148    select count(*) into :misscount from &data where &x is missing;
 
  150 %if &xdiff1=. %then %do;
 
  151    %put ERROR: boxplot: x variable must have at least two values;
 
  152    proc sql noprint; drop table &d_1; quit;
 
  155 %if &misscount>0 %then %do; 
 
  156    %put ERROR: boxplot: Missing values in x variable are not allowed;
 
  157    proc sql noprint; drop table &d_1; quit;
 
  161 %let xmin=%sysevalf(&xmin-&xdiff1);
 
  162 %let xmax=%sysevalf(&xmax+&xdiff1);
 
  165 %if &xdiff1 ne &xdiff2 %then %do; 
 
  166    %put ERROR: boxplot: Values of x variable are not equidistant;
 
  167    proc sql noprint; drop table &d_1; quit;
 
  174    SET &data (KEEP=&x &y &group);
 
  175    IF &group = %if &grouptype=N %then &lower; %else "&lower"; THEN DO;
 
  176       &x = &x - 0.11*&xdiff1;
 
  179       &x = &x + 0.11*&xdiff1;
 
  182 %let d_plot=&syslast;
 
  185 GOPTIONS FTEXT="Helvetica" HTEXT=12pt hsize=16cm vsize=16cm;
 
  186 SYMBOL1 WIDTH = 3 BWIDTH = 3 COLOR = gray  LINE = 2 VALUE = none INTERPOL = BOXJT00 MODE = include;
 
  187 SYMBOL2 WIDTH = 3 BWIDTH = 3 COLOR = black LINE = 1 VALUE = none INTERPOL = BOXJT00 MODE = include;
 
  188 AXIS1 LABEL=(ANGLE=90) MINOR=none;
 
  189 AXIS2 ORDER=(&xmin &xvalues2 &xmax) VALUE=(" " "&xvalues" " ") MINOR=none;
 
  192 ODS PDF FILE="&report";
 
  194 PROC GPLOT DATA=&d_plot;
 
  195    PLOT &y * &x = &group / VAXIS=Axis1 HAXIS=Axis2 LEGEND=Legend1 NOFRAME;