Chapter Contents

Previous

Next
WINDOW

WINDOW



Creates customized windows for your applications

Valid: in a DATA step
Category: Window Display
Type: Declarative


Syntax
Arguments
Details
Field Definitions
Automatic Variables
Displaying Windows
Comparisons
Examples
Example 1: Creating a Single Window
Example 2: Displaying Two Windows Simultaneously
Example 3: Persisting and Nonpersisting Fields
Example 4: Sending a Message
See Also

Syntax

WINDOW window <window-options> field-definition(s);

WINDOW window <window-options> group-definition(s);

Arguments

window
names the window.
Restriction: Window names must conform to SAS naming conventions.

window-options
specifies characteristics of the window as a whole. Specify all window-options before any field or GROUP= specifications. Window-options can include

COLOR=color
specifies the color of the window background for operating environments that have this capability. In other operating environments, this option affects the color of the window border. The following colors are available:
BLACK MAGENTA
BLUE ORANGE
BROWN PINK
CYAN RED
GRAY WHITE
GREEN YELLOW
Default: If you do not specify a color with the COLOR= option, the window's background color is device-dependent instead of black, and the color of a field is device-dependent instead of white.
Tip: The representation of colors may vary, depending on the monitor being used. COLOR= has no effect on monochrome monitors.

COLUMNS=columns
specifies the number of columns in the window.
Default: The window fills all remaining columns in the display; the number of columns that are available depends on the type of monitor that is being used.

ICOLUMN=column
specifies the initial column within the display at which the window is displayed.
Default: SAS displays the window at column 1.

IROW=row
specifies the initial row (or line) within the display at which the window is displayed.
Default: SAS displays the window at row 1.

KEYS=<<libref.>catalog.>keys-entry
specifies the name of a KEYS entry that contains the function key definitions for the window.
Default: SAS uses the current function key settings that are defined in the KEYS window.
Tip: If you specify only an entry name, SAS looks in the SASUSER.PROFILE catalog for a KEYS entry of the name that is specified. You can also specify the three-level name of a KEYS entry, in the form
libref.catalog.keys-entry
Tip: To create a set of function key definitions for a window, use the KEYS window. Define the keys as you want, and use the SAVE command to save the definitions in the SASUSER.PROFILE catalog or in a SAS data library and catalog that you specify.

MENU=<<libref.>catalog.>pmenu-entry
specifies the name of a pull-down menu (pmenu) you have built with the PMENU procedure.
Tip: If you specify only an entry name, SAS looks in the SASUSER.PROFILE catalog for a PMENU entry of the name specified. You can also specify the three-level name of a PMENU entry in the form
libref.catalog.pmenu-entry

ROWS=rows
specifies the number of rows (or lines) in the window.
Default: The window fills all remaining rows in the display.
Tip: The number of rows that are available depends on the type of monitor that is being used.

field-definition
identifies and describes a variable or character string to be displayed in a window or within a group of related fields.
Tip: A window or group can contain any number of fields, and you can define the same field in several groups or windows.
Tip: You can specify multiple field-definitions.
See Also: The form of field-definition is given in Field Definitions.

group-definition
names a group and defines all fields within a group. A group definition consists of two parts: the GROUP= option and one or more field definitions.

GROUP=group
names a group of related fields.
Restriction: group must be a SAS name.
Default: A window contains one unnamed group of fields.
Tip: When you refer to a group in a DISPLAY statement, write the name as window.group.
Tip: A group contains all fields in a window that you want to display at the same time. Display various groups of fields within the same window at different times by naming each group. Choose the group to appear by specifying window.group in the DISPLAY statement.
Tip: Specifying several groups within a window prevents repetition of window options that do not change and helps you to keep track of related displays. For example, if you are defining a window to check data values, arrange the display of variables and messages for most data values in the data set in a group that is named STANDARD. Arrange the display of different messages in a group that is named CHECKIT that appears when data values meet the conditions that you want to check.


Details

Operating Environment Information:   The WINDOW statement has some functionality that is specific to your operating environment. For details, see the SAS documentation for your operating environment.  [cautionend]

You can use the WINDOW statement in the SAS windowing environment, in interactive line mode, or in noninteractive mode to create customized windows for your applications.(footnote 1) Windows that you create can display text and accept input; they have command and message lines. The window name appears at the top of the window. Use commands and function keys with windows that you create. A window definition remains in effect only for the DATA step that contains the WINDOW statement.

Define a window before you display it. Use the DISPLAY statement to display windows that are created with the WINDOW statement. For information about the DISPLAY statement, see DISPLAY.

Field Definitions

Use a field definition to identify a variable or a character string to be displayed, its position, and its attributes. Enclose character strings in quotation marks. The position of an item is its beginning row (or line) and column. Attributes include color, whether you can enter a value into the field, and characteristics such as highlighting.

You can define a field to contain a variable value or a character string, but not both. The form of a field definition for a variable value is

<row column> variable <format> options

The form for a character string is

<row column> 'character-string' options

The elements of a field definition are described here.

row column
identifies the position of the variable or character string.
Default: If you omit row in the first field of a window or group, SAS uses the first row of the window; if you omit row in a later field specification, SAS continues on the row that contains the previous field. If you omit column, SAS uses column 1 (the left border of the window).
Tip: Although you can specify either row or column first, the examples in this book show the row first.

SAS keeps track of its position in the window with a pointer. For example, when you tell SAS to write a variable's value in the third column of the second row of a window, the pointer moves to row 2, column 3 to write the value. Use the pointer controls that are listed here to move the pointer to the appropriate position for a field.

In a field definition, row can be one of these row pointer controls:

#n
specifies row n within the window.
Range: n must be a positive integer.

#numeric-variable
specifies the row within the window that is given by the value of numeric-variable.
Restriction: #numeric-variable must be a positive integer. If the value is not an integer, the decimal portion is truncated and only the integer is used.

#(expression)
specifies the row within the window that is given by the value of expression.
Restriction: expression can contain array references and must evaluate to a positive integer.
Restriction: Enclose expression in parentheses.

/
moves the pointer to column 1 of the next row.

In a field definition, column can be one of these column pointer controls:

@n
specifies column n within the window.
Restriction: n must be a positive integer.

@numeric-variable
specifies the column within the window that is given by the value of numeric-variable.
Restriction: numeric-variable must be a positive integer. If the value is not an integer, the decimal portion is truncated and only the integer is used.

@(expression)
specifies the column within the window that is given by the value of expression.
Restriction: expression can contain array references and must evaluate to a positive integer.
Restriction: Enclose expression in parentheses.

+n
moves the pointer n columns.
Range: n must be a positive integer.

+numeric-variable
moves the pointer the number of columns that is given by the numeric-variable.
Restriction: +numeric-variable must be a positive or negative integer. If the value is not an integer, the decimal portion is truncated and only the integer is used.

variable
names a variable to be displayed or to be assigned the value that you enter at that position when the window is displayed.
Tip: variable can be the name of a variable or of an array reference.
Tip: To allow a variable value in a field to be displayed but not changed by the user, use the PROTECT= option (described later in this section). You can also protect an entire window or group for the current execution of the DISPLAY statement by specifying the NOINPUT option in the DISPLAY statement.
Tip: If a field definition contains the name of a new variable, that variable is added to the data set that is being created (unless you use a KEEP or DROP specification).

format
gives the format for the variable.
Default: If you omit format, SAS uses an informat and format that are specified elsewhere (for example, in an ATTRIB, INFORMAT, or FORMAT statement or permanently stored with the data set) or a SAS default informat and format.
Tip: If a field displays a variable that cannot be changed (that is, you use the PROTECT=YES option), format can be any SAS format or a format that you define with the FORMAT procedure.
Tip: If a field can both display a variable and accept input, you must either specify the informat in an INFORMAT or ATTRIB statement or use a SAS format such as $CHAR. or TIME. that has a corresponding informat.
Tip: If a format is specified, the corresponding informat is assigned automatically to fields that can accept input.
Tip: A format and an informat in a WINDOW statement override an informat and a format that are specified elsewhere.

'character-string'
contains the text of a character string to be displayed.
Restriction: The character string must be enclosed in quotation marks.
Restriction: You cannot enter a value in a field that contains a character string.

options
include any of the following:

ATTR=highlighting-attribute
controls these highlighting attributes of the field:

BLINK
causes the field to blink.

HIGHLIGHT
displays the field at high intensity.

REV_VIDEO
displays the field in reverse video.

UNDERLINE
underlines the field.

Alias: A=
Tip: To specify more than one highlighting attribute, use the form

ATTR=(highlighting-attribute-1, . . . )
Tip: The highlighting attributes that are available depend on the type of monitor that you use.

AUTOSKIP=YES | NO
controls whether the cursor moves to the next unprotected field of the current window or group when you have entered data in all positions of a field.
YES specifies that the cursor moves automatically to the next unprotected field.
NO specifies that the cursor does not move automatically.
Alias: AUTO=
Default: NO

COLOR=color
specifies a color for the variable or character string. The following colors are available:
BLACK MAGENTA
BLUE ORANGE
BROWN PINK
CYAN RED
GRAY WHITE
GREEN YELLOW
Alias: C=
Default: WHITE
Tip: The representation of colors may vary, depending on the monitor you use.
Tip: COLOR= has no effect on monochrome monitors.

DISPLAY=YES | NO
controls whether the contents of a field are displayed.
YES specifies that SAS displays characters in a field as you type them in.
NO specifies that the entered characters are not displayed.
Default: YES

PERSIST=YES | NO
controls whether a field is displayed by all executions of a DISPLAY statement in the same iteration of the DATA step until the DISPLAY statement contains the BLANK option.
YES specifies that each execution of the DISPLAY statement displays all previously displayed contents of the field as well as those that are scheduled for display by the current DISPLAY statement. If the new contents overlap persisting contents, the persisting contents are no longer displayed.
NO specifies that each execution of a DISPLAY statement displays only the current contents of the field.
Default: NO
Tip: PERSIST= is most useful when the position of a field changes in each execution of a DISPLAY statement.
Featured in: Persisting and Nonpersisting Fields

PROTECT=YES | NO
controls whether information can be entered into a field.
YES specifies that you cannot enter information.
NO specifies that you can enter information.
Alias: P=
Default: No
Tip: Use PROTECT= only for fields that contain variables; fields that contain text are automatically protected.

REQUIRED=YES | NO
controls whether a field can be left blank.
NO specifies that you can leave the field blank.
YES specifies that you must enter a value in the field.
Default: NO
Tip: If you try to leave a field blank that was defined with REQUIRED=YES, SAS does not allow you to input values in any subsequent fields in the window.


Automatic Variables

The WINDOW statement creates two automatic SAS variables: _CMD_ and _MSG_.
_CMD_ contains the last command from the window's command line that was not recognized by the window.
Tip: _CMD_ is a character variable of length 80; its value is set to ' ' (blank) before each execution of a DISPLAY statement.
Featured in: Sending a Message
_MSG_ contains a message that you specify to be displayed in the message area of the window.
Tip: _MSG_ is a character variable with length 80; its value is set to ' ' (blank) after each execution of a DISPLAY statement.
Featured in: Sending a Message

Displaying Windows

The DISPLAY statement enables you to display windows. Once you display a window, the window remains visible until you display another window over it or until the end of the DATA step. When you display a window that contains fields into which you can enter values, either enter a value or press ENTER at each unprotected field to cause SAS to proceed to the next display. While a window is being displayed, you can use commands and function keys to view other windows, change the size of the current window, and so on. SAS execution proceeds to the next display only after you have pressed ENTER in all unprotected fields.

A DATA step that contains a DISPLAY statement continues execution until


Comparisons


Examples

Example 1: Creating a Single Window

This DATA step creates a window with a single group of fields:

data _null_;
   window start
          #9  @26 'WELCOME TO THE SAS SYSTEM'
                  color=black
          #12  @19 'THIS PROGRAM CREATES'
          #12  @40 'TWO SAS DATA SETS'
          #14 @26 'AND USES THREE PROCEDURES'
          #18 @27 'Press ENTER to continue';
    display start;
    stop;
run;

[IMAGE]

The START window fills the entire display. The first line of text is black. The other three lines are the default for your operating environment. The text begins in the column that you specified in your program. The START window does not require you to input any values. However, to exit the window do one of the following:

If you omit the STOP statement from this program, the DATA step executes endlessly until you execute END from the window, either with a function key or from the command line. (Because this DATA step does not read any observations, SAS cannot detect an end-of-file to end DATA step execution.)

Example 2: Displaying Two Windows Simultaneously

The following statements assign news articles to reporters. The list of article topics is stored as variable art in SAS data set category.article. This application allows you to assign each topic to a writer and to view the accumulating assignments. The program creates a new SAS data set named Assignment.

libname category 'SAS-data-library';

data Assignment;
   set category.article end=final;
   drop a b j s o;
   window Assignment irow=1 rows=12 color=white
          #3 @10 'Article:' +1 art protect=yes
          'Name:' +1 name $14.;
   window Showtotal irow=20 rows=12 color=white
          group=subtotal
          #1 @10 'Adams has' +1 a
          #2 @10 'Brown has' +1 b
          #3 @10 'Johnson has' +1 j
          #4 @10 'Smith has' +1 s
          #5 @10 'Other has' +1 o
          group=lastmessage
          #8 @10
          'ALL ARTICLES ASSIGNED. 
          Press ENTER to stop processing.';
   display Assignment blank;
   if name='Adams' then a+1;
   else if name='Brown' then b+1;
   else if name='Johnson' then j+1;
   else if name='Smith' then s+1;
   else o+1;
   display Showtotal.subtotal blank noinput;
   if final then display Showtotal.lastmessage;
run;

When you execute the DATA step, the following windows appear.

[IMAGE]

In the Assignment window (located at the top of the display), you see the name of the article and a field into which you enter a reporter's name. After you type a name and press ENTER, SAS displays the Showtotal window (located at the bottom of the display) which shows the number of articles that are assigned to each reporter (including the assignment that you just made). As you continue to make assignments, the values in the Showtotal window are updated. During the last iteration of the DATA step, SAS displays the message that all articles are assigned, and instructs you to press ENTER to stop processing.

Example 3: Persisting and Nonpersisting Fields

This example demonstrates the PERSIST= option. You move from one window to the other by positioning the cursor in the current window and pressing ENTER.

data _null_;
   array row{3} r1-r3;
   array col{3} c1-c3;
   input row{*} col{*};
   window One
          rows=20 columns=36
          #1 @14 'PERSIST=YES' color=black
          #(row{i}) @(col{i}) 'Hello'
          color=black persist=yes;

   window Two
          icolumn=43 rows=20 columns=36
          #1 @14 'PERSIST=NO' color=black
          #(row{i}) @(col{i}) 'Hello'
          color=black persist=no;
   do i=1 to 3;
      display One;
      display Two;
   end;
   datalines;
5 10 15 5 10 15
;
The following windows show the results of this DATA step after its third iteration.

[IMAGE]

Note that window One shows Hello in all three positions in which it was displayed. Window Two shows only the third and final position in which Hello was displayed.

Example 4: Sending a Message

This example uses the _CMD_ and _MSG_ automatic variables to send a message when you execute an erroneous windowing command in a window that is defined with the WINDOW statement:

if _cmd_ ne ' ' then
   _msg_='CAUTION: UNRECOGNIZED COMMAND' || _cmd_;
When you enter a command that contains an error, SAS sets the value of _CMD_ to the text of the erroneous command. Because the value of _CMD_ is no longer blank, the IF statement is true. The THEN statement assigns to _MSG_ the value that is created by concatenating CAUTION: UNRECOGNIZED COMMAND and the value of _CMD_ (up to a total of 80 characters). The next time a DISPLAY statement displays that window, the message line of the window displays
CAUTION: UNRECOGNIZED COMMAND command
Command is the erroneous windowing command.

See Also

Statements:
DISPLAY
"The PMENU Procedure" in SAS Procedures Guide


FOOTNOTE 1:  You cannot use the WINDOW statement in batch mode because no terminal is connected to a batch executing process. [arrow]


Chapter Contents

Previous

Next

Top of Page

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