FSVIEW Procedure Windows |
The FSVIEW procedure enables you to define formulas that perform computations and otherwise manipulate variables. Formulas are SAS expressions that calculate values for variables in the FSVIEW window. You can define formulas for variables in the data set, or you can create computed variables to display the formula results.
The effect of assigning a formula to a data set variable depends on whether the FSVIEW window is open for browsing or editing. If the window is open for browsing, then the result of computations performed by the assigned formula is displayed in the variable's column in the FSVIEW window, but the variable value in the data set is not affected. If the window is open for editing, then the result of the formula computations replaces the value that is stored in the data set as well as the value in the FSVIEW window.
Computed variables exist only in the FSVIEW window to show the result of computations that are performed by a formula; they are not added to the displayed data set. The values of computed variables cannot be edited. However, within the FSVIEW window computed variables can be manipulated just like data set variables. The only exception is that you cannot use the SORT command to sort the data set according to the values of a computed variable.
Use the DEFINE command to define formulas. The FSVIEW procedure provides two ways to use the DEFINE command:
Use the DEFINE command alone or with only the variable-name argument to open the FSVIEW Define window. In this window you can enter all the information necessary to define the formula. You can also use this form of the command to open the FSVIEW Define window to edit an existing formula. See Defining Formulas in the FSVIEW Define Window for more information on using the FSVIEW Define window.
Supply the formula as an argument with the DEFINE command. Separate the formula from the variable name with an equal sign (=).
Formulas are stored in SAS catalog entries that have the type FORMULA. See Creating FSVIEW Applications for details.
How Formulas Are Evaluated |
Formulas are evaluated in the order in which the corresponding variables appear in the FSVIEW window. It is the order of the variables, not the order in which the formulas are defined, that determines the evaluation order. Formulas are evaluated first for any ID variables, then for the remaining variables in left-to-right order. After the formulas for displayed variables are evaluated, any formulas assigned to variables that are dropped from the FSVIEW window are evaluated, in the order in which the variables are dropped.
If you use a computed variable in the formula definition for another variable, the variable that is named in the formula must appear in the FSVIEW window to the left of the variable for which the formula is defined. Otherwise, the value of the variable in the formula is missing when the formula is evaluated.
When the FSVIEW window is displayed or redrawn, the formulas are evaluated for all displayed observations. When an observation is edited, formulas are evaluated for the edited observation only.
Using SAS Component Language in Formulas |
Formulas can also include any valid SAS Component Language functions or statements except those that are valid only in SAS/AF software and the following statements:
CONTROL ALWAYS | ERROROFF | PROTECT |
CURSOR | ERRORON | UNPROTECT |
The MODIFIED, ERROR, and CUROBS functions are valid.
Each formula that you define is treated as a block of SCL code. When you define a formula, the FSVIEW procedure internally adds a label for the formula and a RETURN statement so that each formula can be treated as a separate SCL block. (The label is the same as the variable name.) The SCL code segments are compiled individually when the formulas are defined.
For example, suppose you define a computed variable that is named MODSTAT with the following formula:
modstat=modified(begdate)
The SCL block for the MODSTAT variable would be stored as follows:
MODSTAT: modstat=modified(begdate);RETURN;
The blocks are executed in the order in which the corresponding variables appear in the FSVIEW window.
Refer to SAS Component Language: Reference for details about including SAS Component Language in FSVIEW formulas.
Defining Formulas in the FSVIEW Define Window |
When you issue a DEFINE command in the FSVIEW window without specifying a formula for the variable, the FSVIEW Define window is opened so that you can enter the formula definition and other variable attributes. The FSVIEW Define Window shows the FSVIEW Define window that is opened for a variable named ENDDATE:
The FSVIEW Define window includes the following fields:
is the name of the variable with which this formula is associated. You can change the name in this field while the FSVIEW Define window is open to change the variable for which the formula is defined. If you specify the name of a variable that has an existing formula definition, the remaining fields in this window are filled with values from the current definition.
is the variable type. To select a type, position the cursor on the corresponding term and press ENTER. The default is NUMERIC.
is the format that determines how the variable is displayed. The format also determines the width of the variable's column in the FSVIEW window. If you do not specify a format, a default is used:
BEST12. for numeric variables
$8. for character variables.
is the informat that determines how values that are entered in the variable's column in the FSVIEW window are interpreted. If you do not specify an informat, a default is used:
12. for numeric variables
$8. for character variables.
is a descriptive label up to 256 characters long. (The FSVIEW procedure does not display variable labels.)
At the bottom of the window are four lines for entering the formula. The FSVIEW Define window supplies the variable name and the equal sign that begin the definition.
Formulas that you define in the FSVIEW Define window can consist of more than one statement. If you use multiple statements, separate the statements with semicolons. The definition can include as many statements as you can fit in the space provided.
The four lines of text in the FSVIEW Define window are seen as a single line of text when the formula is compiled. Spaces are not automatically inserted between the end of one line in the window and the beginning of the next. If you do not leave spaces between words at the line breaks, you may encounter syntax errors when the formula is compiled.
The following section describes the commands you can use in the FSVIEW Define window.
FSVIEW Define Window Commands |
In addition to the global commands that are discussed in SAS/FSP Software Global Commands, you can use the following commands in the FSVIEW Define window:
closes the FSVIEW Define window without recording the formula or variable attributes that were entered in the window. Once you open the FSVIEW Define window, you must use this command if you want to close the window without entering a formula definition.
compiles the current formula and reports whether it is a valid SAS expression.
compiles the current formula. If the formula is valid, the FSVIEW Define window is closed, the formula definition is recorded in the FORMULA entry, and you return to the FSVIEW window. If the formula contains errors, an error message is displayed and the FSVIEW Define window remains open.
Reviewing Formula Definitions |
You can browse existing formula definitions in the FSVIEW REVIEW window. Use the REVIEW command in the FSVIEW window to open the FSVIEW REVIEW window. Viewing Formulas in the FSVIEW REVIEW Window shows a FSVIEW REVIEW window that contains two formula definitions.
Viewing Formulas in the FSVIEW REVIEW Window
The FSVIEW REVIEW window displays the formulas for browsing only. You cannot make changes to the formulas in this window. The formula definitions are listed in the order in which they are entered.
FSVIEW REVIEW Window Commands |
The FSVIEW REVIEW window uses the SAS text editor. All text editor browsing commands are valid in this window. Refer to the online Help for Base SAS software for more information on the commands that can be used in text editor windows.
Use the END command to close the FSVIEW REVIEW window and return to the FSVIEW window.
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.