Running Custom Analyses


Example: Create an Action Menu

You can create a custom menu for a plot and associate one or more IMLPlus statements with each item on the menu. Such a menu is referred to as an action menu. To display a plot’s action menu, press F11 while the plot’s window is active. Selecting an item on the menu executes the IMLPlus statements that are associated with that item.

Several previous chapters use action menus to run an analysis on a plot. For example, Figure 12.14 and Figure 18.9 show action menus attached to plots.

Action menus are described in the SAS/IML Studio online Help, in the section called "The Action Menu" in the chapter titled "The Plots."

As an example, the following statements create a histogram and attach an action menu to the plot. When the menu item is selected, the module PrintMean is executed. If the X variable is numeric, then the PrintMean module gets the data that are associated with the X variable of the plot and computes the mean value of these data.

x = normal( j(100,1,1) );
declare Histogram plot;
plot = Histogram.Create("Histogram", x);
plot.AppendActionMenuItem("Print Mean", "run PrintMean();");
/* Press F11 in the plot window and select the menu item. */

/* module to run when menu item is selected */
start PrintMean();
   declare Plot plot;
   plot = DataView.GetInitiator();  /* get the active plot */
   plot.GetVars(ROLE_X, VarName);   /* get the X var name */

   declare DataObject dobj;
   dobj = plot.GetDataObject();     /* get the DataObject */
   if dobj.IsNumeric(VarName) then do;
      dobj.GetVarData(VarName, x);  /* get the X values */
      mean = x[:];                  /* compute the mean */
      print "The mean X value is " mean;
   end;
finish;