PMENU Procedure

Example 4: Creating Menus for a DATA Step Window Application

Features:

DIALOG statement

SELECTION statement

Other features:

FILENAME statement

Details

This example defines an application that enables the user to enter human resources data for various departments, and to request reports from the data sets that are created by the data entry.
The first part of the example describes the PROC PMENU step that creates the menus. The subsequent sections describe how to use the menus in a DATA step window application.
Tasks include these:
  • associating customized menus with a DATA step window
  • creating menus for a DATA step window
  • submitting SAS code from a menu selection
  • creating a menu selection that calls a dialog box

Program

libname proclib
'SAS-data-library';
filename de     'external-file';
filename prt    'external-file';
 proc pmenu catalog=proclib.menus;
    menu select;
   item 'File' menu=f;
   item 'Data_Entry' menu=deptsde;
   item 'Print_Report' menu=deptsprt;
   menu f;
      item 'End this window' selection=endwdw;
      item 'End this SAS session' selection=endsas;
      selection endwdw 'end';
      selection endsas 'bye';
    menu deptsde;
       item 'For Dept01' selection=de1;
       item 'For Dept02' selection=de2;
       item 'Other Departments' dialog=deother;
       selection de1 'end;pgm;include de;change xx 01;submit';
       selection de2 'end;pgm;include de;change xx 02;submit';
       dialog deother 'end;pgm;include de;c deptxx @1;submit';
          text #1 @1 'Enter department name';
          text #2 @3 'in the form DEPT99:';
          text #2 @25 len=7;
      menu deptsprt;
         item 'For Dept01' selection=prt1;
         item 'For Dept02' selection=prt2;
         item 'Other Departments' dialog=prother;
         selection prt1
               'end;pgm;include prt;change xx 01 all;submit';
         selection prt2
               'end;pgm;include prt;change xx 02 all;submit';
      dialog prother 'end;pgm;include prt;c deptxx @1 all;submit';
         text #1 @1 'Enter department name';
         text #2 @3 'in the form DEPT99:';
         text #2 @25 len=7;
   run;
     menu entrdata;
        item 'File' menu=f;
        menu f;
           item 'End this window' selection=endwdw;
           item 'End this SAS session' selection=endsas;
           selection endwdw 'end';
           selection endsas 'bye';
   run;
quit;

Program Description

Declare the PROCLIB library. The PROCLIB library is used to store menu definitions.
libname proclib
'SAS-data-library';
Declare the DE and PRT filenames. The FILENAME statements define the external files in which the programs to create the windows are stored.
filename de     'external-file';
filename prt    'external-file';
Specify the catalog for storing menu definitions. Menu definitions will be stored in the PROCLIB.MENUCAT catalog.
 proc pmenu catalog=proclib.menus;
Specify the name of the catalog entry. The MENU statement specifies SELECT as the name of the catalog entry. The menus are stored in the catalog entry PROCLIB.MENUS.SELECT.PMENU.
    menu select;
Design the menu bar. The ITEM statements specify the three items on the menu bar. The value of the MENU= option is used in a subsequent MENU statement.
   item 'File' menu=f;
   item 'Data_Entry' menu=deptsde;
   item 'Print_Report' menu=deptsprt;
Design the File menu. This group of statements defines the selections under File. The value of the SELECTION= option is used in a subsequent SELECTION statement.
   menu f;
      item 'End this window' selection=endwdw;
      item 'End this SAS session' selection=endsas;
      selection endwdw 'end';
      selection endsas 'bye';
Design the Data_Entry menu. This group of statements defines the selections under Data_Entry on the menu bar. The ITEM statements specify that For Dept01 and For Dept02 appear under Data_Entry. The value of the SELECTION= option equates to a subsequent SELECTION statement, which contains the string of commands that are actually submitted. The value of the DIALOG= option equates to a subsequent DIALOG statement, which describes the dialog box that appears when this item is selected.
    menu deptsde;
       item 'For Dept01' selection=de1;
       item 'For Dept02' selection=de2;
       item 'Other Departments' dialog=deother;
Specify commands under the Data_Entry menu. The commands in single quotation marks are submitted when the user selects For Dept01 or For Dept02. The END command ends the current window and returns to the PROGRAM EDITOR window so that further commands can be submitted. The INCLUDE command includes the SAS statements that create the data entry window. The CHANGE command modifies the DATA statement in the included program so that it creates the correct data set. The SUBMIT command submits the DATA step program.
       selection de1 'end;pgm;include de;change xx 01;submit';
       selection de2 'end;pgm;include de;change xx 02;submit';
Design the DEOTHER dialog box. The DIALOG statement defines the dialog box that appears when the user selects Other Departments. The DIALOG statement modifies the command string so that the name of the department that is entered by the user is used to change deptxx in the SAS program that is included. The first two TEXT statements specify text that appears in the dialog box. The third TEXT statement specifies an input field. The name that is entered in this field is substituted for the @1 in the DIALOG statement.
       dialog deother 'end;pgm;include de;c deptxx @1;submit';
          text #1 @1 'Enter department name';
          text #2 @3 'in the form DEPT99:';
          text #2 @25 len=7;
Design the Print_Report menu. This group of statements defines the choices under the Print_Report item. These ITEM statements specify that For Dept01 and For Dept02 appear in the menu. The value of the SELECTION= option equates to a subsequent SELECTION statement, which contains the string of commands that are actually submitted.
      menu deptsprt;
         item 'For Dept01' selection=prt1;
         item 'For Dept02' selection=prt2;
         item 'Other Departments' dialog=prother;
Specify commands for the Print_Report menu. The commands in single quotation marks are submitted when the user selects For Dept01 or For Dept02. The END command ends the current window and returns to the PROGRAM EDITOR window so that further commands can be submitted. The INCLUDE command includes the SAS statements that print the report. (For more information, see Printing a Program.) The CHANGE command modifies the PROC PRINT step in the included program so that it prints the correct data set. The SUBMIT command submits the PROC PRINT program.
         selection prt1
               'end;pgm;include prt;change xx 01 all;submit';
         selection prt2
               'end;pgm;include prt;change xx 02 all;submit';
Design the PROTHER dialog box. The DIALOG statement defines the dialog box that appears when the user selects Other Departments. The DIALOG statement modifies the command string so that the name of the department that is entered by the user is used to change deptxx in the SAS program that is included. The first two TEXT statements specify text that appears in the dialog box. The third TEXT statement specifies an input field. The name entered in this field is substituted for the @1 in the DIALOG statement.
      dialog prother 'end;pgm;include prt;c deptxx @1 all;submit';
         text #1 @1 'Enter department name';
         text #2 @3 'in the form DEPT99:';
         text #2 @25 len=7;
End this RUN group.
   run;
Specify a second catalog entry and menu bar. The MENU statement specifies ENTRDATA as the name of the catalog entry that this RUN group is creating. File is the only item on the menu bar. The selections available are End this window and End this SAS session.
     menu entrdata;
        item 'File' menu=f;
        menu f;
           item 'End this window' selection=endwdw;
           item 'End this SAS session' selection=endsas;
           selection endwdw 'end';
           selection endsas 'bye';
   run;
quit;

Other Examples

Associating a Menu with a Window

The first group of statements defines the primary window for the application. These statements are stored in the file that is referenced by the HRWDW fileref:
The WINDOW statement creates the HRSELECT window. MENU= associates the PROCLIB.MENUS.SELECT.PMENU entry with this window.
   data _null_;
      window hrselect menu=proclib.menus.select
      #4  @10 'This application allows you to'
      #6  @13 '- Enter human resources data for'
      #7  @15 'one department at a time.'
      #9  @13 '- Print reports on human resources data for'
      #10 @15 'one department at a time.'
      #12 @13 '- End the application and return to the PGM window.'
      #14 @13 '- Exit from the SAS System.'
      #19 @10 'You must have the menus turned on.';
The DISPLAY statement displays the HRSELECT window.
      display hrselect;
   run;
The HRSELECT window that is displayed by the DISPLAY statement:
HRSELECT Window

Using a Data Entry Program

When the user selects Data_Entry from the menu bar in the HRSELECT window, a menu is displayed. When the user selects one of the listed departments or chooses to enter a different department, the following statements are invoked. These statements are stored in the file that is referenced by the DE fileref.
The WINDOW statement creates the HRDATA window. MENU= associates the PROCLIB.MENUS.ENTRDATA.PMENU entry with the window.
  data proclib.deptxx;
      window hrdata menu=proclib.menus.entrdata
      #5  @10 'Employee Number'
      #8  @10 'Salary'
      #11 @10 'Employee Name'
      #5  @31 empno $4.
      #8  @31 salary 10.
      #11 @31 name $30.
      #19 @10 'Press ENTER to add the observation to the data set.';
The DISPLAY statement displays the HRDATA window.
      display hrdata;
  run;
The %INCLUDE statement recalls the statements in the file HRWDW. The statements in HRWDW redisplay the primary window. See the HRSELECT window
  filename hrwdw 'external-file';
  %include hrwdw;
  run;
The SELECTION and DIALOG statements in the PROC PMENU step modify the DATA statement in this program so that the correct department name is used when the data set is created. That is, if the user selects Other Departments and enters DEPT05, then the DATA statement is changed by the command string in the DIALOG statement to
   data proclib.dept05;
The following figure displays the data entry window, HRDATA.
HRDATA Window

Printing a Program

When the user selects Print_Report from the menu bar, a menu is displayed. When the user selects one of the listed departments or chooses to enter a different department, the following statements are invoked. These statements are stored in the external file referenced by the PRT fileref.
PROC PRINTTO routes the output to an external file.
   proc printto
file='external-file' new;
   run;
   libname proclib
'SAS-data-library';

   proc print data=proclib.deptxx;
      title 'Information for deptxx';
   run;
This PROC PRINTTO step restores the default output destination. See PRINTTO Procedure
   proc printto;
   run;
The %INCLUDE statement recalls the statements in the file HRWDW. The statements in HRWDW redisplay the primary window.
   filename hrwdw 'external-file';
   %include hrwdw;
   run;