2.3.1.2.1.1 Assignment StatementsAssignment-stmts
The assignment statement takes the general form:
LHS = expression ;
expression (RHS, right-hand side) is evaluated and put into LHS (left-hand side). If LHS does not exist, it is created if possible, otherwise an error will be reported.
When a new data object is created with an assignment statement, the object created is:
- A string variable if LHS ends with a $ as in stringVar$ = "Hello."
- A numeric variable if expression evaluates to a scalar.
- A dataset if expression evaluates to a range.
When new values are assigned to an existing data object, the following conventions apply:
- If LHS is a dataset and expression is a scalar, every value in LHS is set equal to expression.
- If LHS is a numeric variable, then expression must evaluate into a scalar. If expression evaludate into a dataset, LHS retrieves the first element of the dataset.
- If both LHS and expression represent datasets, each value in LHS is set equal to the corresponding value in expression.
- If LHS is a string, then expression is assumed to be a string expression.
- If the LHS is the object.property notation, with or without $ at the end, then this notation is used to set object properties, such as the number of columns in a worksheet, like wks.ncols=3;
Examples of Assignment Statements
Assign the variable B equal to 2.
B = 2;
Assign Test equal to B raised to the third power.
Test = B^3;
Assign %A equal to Austin TX.
%A = Austin TX;
Assign every value in Book1_B to 4.
Book1_B = 4;
Assign each value in Book2_B to the corresponding position in Book1_B.
Book1_B = Book2_B;
Sets the row heading width for the Book1 worksheet to 100, using the worksheet object's rhw property. The doc -uw command refreshes the window.
Book1!wks.rhw = 100; doc -uw;
The calculation is carried out for the values at the corresponding index numbers in more and yetmore. The result is put into myData at the same index number.
myData = 3 * more + yetmore;
Note: If a string register to the left of the assignment operator is enclosed in parentheses, the string register is substitution processed before assignment. For example:
%B = DataSet;
(%B) = 2 * %B;
The values in DataSet are multiplied by 2 and put back into DataSet. %B still holds the string "DataSet".
Similar to string registers, the assignment statement is also used for string variables, like:
fname$=fdlg.path$+"test.csv";
In this case, the expression is a string expression which can be string literals, string variables, or a concatenation of multiple strings with the + character.
|