Statistical Graphics (SG) Annotation does not support BY-group processing


Statistical Graphics (SG) Annotation does not support BY-group processing. As a result, all of the annotation appears in the graph for each BY-variable value.

To circumvent the problem, define a macro to run the statistical graphics procedure for each value of the BY variable as shown in the following sample code using the SGPLOT procedure:

proc sort data=sashelp.class out=class; 
   by sex;
run;

%macro plot(byval);
   data anno;
      set class;
      where sex="&byval";
      length label $8;
      drawspace='datavalue';
      function='text';
      x1=age;
      y1=height;
      anchor='bottomleft';
      label=name;
      textcolor='blue';
   run;

   title "Class Height by Age for &byval";
   proc sgplot data=class sganno=anno;
      where sex="&byval";
      scatter x=age y=height;
      xaxis offsetmin=0.02 offsetmax=0.05;
   run;
   title;
%mend;

data _null_;
   set class;
   by sex;
   if first.sex then call execute('%PLOT(' || sex ||')');
run;