Chapter Contents |
Previous |
Next |
The PMENU Procedure |
Procedure features: |
| ||||||||||||
Other features: | SAS macro invocation |
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
Program |
libname proclib 'SAS-data-library';
proc pmenu catalog=proclib.menucat; |
menu project; |
item 'File' menu=f; item 'Edit' menu=e; item 'Scroll' menu=s; item 'Subset' menu=sub; item 'Help' menu=h; |
menu f; item 'Goback' selection=g; item 'Save'; selection g 'end'; |
menu e; item 'Cancel'; item 'Add'; |
menu s; item 'Next Obs' selection=n; item 'Prev Obs' selection=p; item 'Top'; item 'Bottom'; selection n 'forward'; selection p 'backward'; |
menu sub; item 'Where' dialog=d1; item 'Where Clear'; |
menu h; item 'Keys'; item 'About this application' selection=hlp; selection hlp 'sethelp proclib.menucat.staffhlp.help;help'; |
dialog d1 '%%wbuild(%1,%2,@1,%3)'; |
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'; |
text #13 @1 'Enter Value for Search:'; text #13 @25 len=6; |
Associating a Menu Bar with an FSEDIT Session |
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; run;
To associate the customized menu bar menu with the FSEDIT session, do any one of the following:
setpmenu proclib.menucat.project.pmenu
Turn on the menus by entering PMENU ON on the command line.
fseinit: call execcmd('setpmenu proclib.menucat.project.pmenu; pmenu on;'); return; init: return; main: return; term: return;
How the WBUILD Macro Works |
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:
NE
,
NW
,
SE
, or
SW
, becomes the value of the macro
parameter REGION.
pol_a,2
or
pol_b,4
become the values of the PREFIX
and NUMVAR macro parameters. The comma is part of the value that is passed
to the WBUILD macro and serves to delimit the two parameters, PREFIX and NUMVAR.
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
REGION | SW |
|
---|---|---|
PREFIX | pol_a |
|
NUMVAR | 2 | |
VALUE | .50 | |
OPERATOR | GE |
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="®ion" 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; OR %end; %end; ) %end; %mend wbuild;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.