Window and Display Features


Creating a Display Window for Data Entry

Suppose that your application is a data entry system for a mailing list. You want to create a data set called MAILLIST by prompting the user with a window that displays all the entry fields. You want the data entry window to look as follows:

   +--MAILLIST----------------------------------------------+
   | Command==>                                             |
   |                                                        |
   |                                                        |
   | NAME:                                                  |
   | ADDRESS:                                               |
   | CITY: STATE: ZIP:                                      |
   | PHONE:                                                 |
   |                                                        |
   +--------------------------------------------------------+

The process for creating a display window for this application consists of

  • initializing the variables

  • creating a SAS data set

  • defining a module for collecting data that

    1. defines a window

    2. defines the data fields

    3. defines a loop for collecting data

    4. provides an exit from the loop

  • executing the data-collecting routine

The whole system can be implemented with the following code to define modules INITIAL and MAILGET:

    /*   module to initialize the variables                     */
    /*                                                          */
    start initial;
       name='        ';
       addr='                     ';
       city='                     ';
       state='  ';
       zip='    ';
       phone='        ';
    finish initial;

This defines a module named INITIAL that initializes the variables you want to collect. The initialization sets the string length for the character fields. You need to do this prior to creating your data set.

Now define a module for collecting the data, as follows:

    /* module to collect data                                   */
    /*                                                          */
    start mailget;
    /* define the window                                        */
       window maillist cmndline=cmnd msgline=msg
          group=addr
          #2 " NAME: " name
          #3 " ADDRESS:" addr
          #4 " CITY: " city +2 "STATE: " state +2 "ZIP: " zip
          #5 " PHONE: " phone;
    /*                                                          */
    /* collect addresses until the user enters exit             */
    /*                                                          */
       do until(cmnd="EXIT");
          run initial;
          msg="ENTER SUBMIT TO APPEND OBSERVATION, EXIT TO END";
    /*                                                          */
    /* loop until user types submit or exit                     */
    /*                                                          */
          do until(cmnd="SUBMIT"|cmnd="EXIT");
             display maillist.addr;
          end;
          if cmnd="SUBMIT" then append;
       end;
       window close=maillist;
    finish mailget;
    /* initialize variables                                     */
    run initial;
    /* create the new data set                                  */
    create maillist var{name addr city state zip phone};
    /* collect data                                             */
    run mailget;
    /* close the new data set                                   */
    close maillist;

In the module MAILGET, the WINDOW statement creates a window named MAILLIST with a group of fields (the group is named ADDR) presenting data fields for data entry. The program sends messages to the window through the MSGLINE= variable MSG. The program receives commands you enter through the CMNDLINE= variable CMND.

You can enter data into the fields after each prompt field. After you are finished with the entry, press a key defined as SUBMIT, or type SUBMIT in the command field. The data are appended to the data set MAILLIST. When data entry is complete, type EXIT in the command field. If you enter a command other than SUBMIT, EXIT, or a valid SAS windowing environment command in the command field, you get the following message on the message line:

   ENTER SUBMIT TO APPEND OBSERVATION, EXIT TO END.