Chapter Contents


The PMENU Procedure

Example 3: Creating a Dialog Box to Search Multiple Variables

Procedure features:
DIALOG statement
SAS macro invocation
ITEM statement
DIALOG= option
RADIOBOX statement option:
RBUTTON statement option:
Other features: SAS macro invocation

This example shows how to modify the menu bar in an FSEDIT session to enable a search for one value across multiple variables. The example creates customized menus to use in an FSEDIT session. The menu structure is the same as in the preceding example, except for the WHERE dialog box.

Once selected, the menu item invokes a macro. The user input becomes values for macro parameters. The macro generates a WHERE command that expands to include all the variables needed for the search.

Tasks include


libname proclib 'SAS-data-library';
 Note about code
proc pmenu catalog=proclib.menucat;
 Note about code
   menu project;

 Note about code
      item 'File' menu=f;
      item 'Edit' menu=e;
      item 'Scroll' menu=s;
      item 'Subset' menu=sub;
      item 'Help' menu=h;
 Note about code
      menu f;
         item 'Goback' selection=g;
         item 'Save';
         selection g 'end';

 Note about code
      menu e;
         item 'Cancel';
         item 'Add';
 Note about code
      menu s;
         item 'Next Obs' selection=n;
         item 'Prev Obs' selection=p;
         item 'Top';
         item 'Bottom';
         selection n 'forward';
         selection p 'backward';
 Note about code
      menu sub;
         item 'Where' dialog=d1;
         item 'Where Clear';
 Note about code
      menu h;
         item 'Keys';
         item 'About this application' selection=hlp;
         selection hlp 'sethelp;help';

 Note about code
       dialog d1 '%%wbuild(%1,%2,@1,%3)';

 Note about code
          text #1 @1 'Choose a region:';
          radiobox default=1;
             rbutton #3 @5 'Northeast' substitute='NE';
             rbutton #4 @5 'Northwest' substitute='NW';
             rbutton #5 @5 'Southeast' substitute='SE';
             rbutton #6 @5 'Southwest' substitute='SW';

 Note about code
          text #8 @1 'Choose a contaminant:';
          radiobox default=1;
             rbutton #10 @5  'Pollutant A' substitute='pol_a,2';
             rbutton #11 @5  'Pollutant B' substitute='pol_b,4';

 Note about code
          text #13 @1 'Enter Value for Search:';
          text #13 @25 len=6;

 Note about code
          text #15 @1 'Choose a comparison criterion:';
          radiobox default=1;
             rbutton #16 @5 'Greater Than or Equal To'
             rbutton #17 @5 'Less Than or Equal To'
             rbutton #18 @5 'Equal To' substitute='EQ';

 Note about figure


Associating a Menu Bar with an FSEDIT Session
The SAS data set PROCLIB.LAKES has data about several lakes. Two pollutants, pollutant A and pollutant B, were tested at each lake. Tests were conducted for pollutant A twice at each lake, and the results are recorded in the variables POL_A1 and POL_A2. Tests were conducted for pollutant B four times at each lake, and the results are recorded in the variables POL_B1 - POL_B4. Each lake is located in one of four regions. The following output lists the contents of PROCLIB.LAKES:

                                 PROCLIB.LAKES                                 1

region    lake         pol_a1    pol_a2    pol_b1    pol_b2    pol_b3    pol_b4

  NE      Carr          0.24      0.99      0.95      0.36      0.44      0.67 
  NE      Duraleigh     0.34      0.01      0.48      0.58      0.12      0.56 
  NE      Charlie       0.40      0.48      0.29      0.56      0.52      0.95 
  NE      Farmer        0.60      0.65      0.25      0.20      0.30      0.64 
  NW      Canyon        0.63      0.44      0.20      0.98      0.19      0.01 
  NW      Morris        0.85      0.95      0.80      0.67      0.32      0.81 
  NW      Golf          0.69      0.37      0.08      0.72      0.71      0.32 
  NW      Falls         0.01      0.02      0.59      0.58      0.67      0.02 
  SE      Pleasant      0.16      0.96      0.71      0.35      0.35      0.48 
  SE      Juliette      0.82      0.35      0.09      0.03      0.59      0.90 
  SE      Massey        1.01      0.77      0.45      0.32      0.55      0.66 
  SE      Delta         0.84      1.05      0.90      0.09      0.64      0.03 
  SW      Alumni        0.45      0.32      0.45      0.44      0.55      0.12 
  SW      New Dam       0.80      0.70      0.31      0.98      1.00      0.22 
  SW      Border        0.51      0.04      0.55      0.35      0.45      0.78 
  SW      Red           0.22      0.09      0.02      0.10      0.32      0.01 

A DATA step creates PROCLIB.LAKES.

The following statements initiate a PROC FSEDIT session for PROCLIB.LAKES:

proc fsedit data=proclib.lakes screen=proclib.lakes;

To associate the customized menu bar menu with the FSEDIT session, do any one of the following:

How the WBUILD Macro Works
Consider how you would learn whether any of the lakes in the Southwest region tested for a value of .50 or greater for pollutant A. Without the customized menu item, you would issue the following WHERE command in the FSEDIT window:

where region="SW" and (pol_a1 ge .50 or pol_a2 ge .50);

Using the custom menu item, you would select Southwest, Pollutant A, enter .50 as the value, and choose Greater Than or Equal To as the comparison criterion. Two lakes, New Dam and Border, meet the criteria.

The WBUILD macro uses the four pieces of information from the dialog box to generate a WHERE command:

To see how the macro works, again consider the following example, in which you want to know if any of the lakes in the southwest tested for a value of .50 or greater for pollutant A. The values of the macro parameters would be

PREFIX pol_a

The first %IF statement checks to make sure that the user entered a value. If a value has been entered, the macro begins to generate the WHERE command. First, the macro creates the beginning of the WHERE command:

where region="SW" and (

Next, the %DO loop executes. For pollutant A, it executes twice because NUMVAR=2. In the macro definition, the period in &prefix.&i concatenates pol_a with 1 and with 2. At each iteration of the loop, the macro resolves PREFIX, OPERATOR, and VALUE, and it generates a part of the WHERE command. On the first iteration, it generates

pol_a1 GE .50

The %IF statement in the loop checks to see if the loop is working on its last iteration. If it is not, the macro makes a compound WHERE command by putting an OR between the individual clauses. The next part of the WHERE command becomes

OR pol_a2 GE .50

The loop ends after two executions for pollutant A, and the macro generates the last of the WHERE command:


Results from the macro are placed on the command line. The following code is the definition of the WBUILD macro. The underlined code shows the parts of the WHERE command that are text strings that the macro does not resolve:

%macro wbuild(region,prefix,numvar,value,operator);
       /* check to see if value is present */
    %if &value ne %then %do;            
       where region="&region" AND (
               /* If the values are character,     */
               /* enclose &value in double quotes. */
         %do i=1 %to &numvar;
             &prefix.&i &operator &value  
                /* if not on last variable,  */
                /* generate 'OR'             */
            %if &i ne &numvar %then %do;

%mend wbuild;

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.