|
Forms | COMPUTE |
These are stand alone commands where the values are computed each time the command is traversed. These commands do not affect the current cursor position.
COMPUTE
and IF
are also options
on the INITIAL
and FINAL
clauses of the
MENU,
RECORD,
TABLE,
CALL and
FIELD
commands. These options use expressions and conditions in exactly
the same manner.
COMPUTE variable =
expression
The variable specified on the left side of the equal sign must be defined in the
record or table accessed by the current screen or in the
DECLARE clause
of the FORM
command.
COMPUTE AVERAGE = (VARX + VARY + VARZ) / 3
IF
(condition)
variable =
expression
The variable specified on the left side of the equal sign must be defined in the
record or table accessed by the current screen or in the
DECLARE
clause of the FORM
command. The
variable is only calculated if the condition is true.
Example: To give a $1,000 raise to all technical writers
(position = 10):
IF (position eq 10) salary = salary + 1000
IF
condition may include the following operators:
EQ or = or IS
NE or ><
LT or <
LE or <=
GT or >
GE or >=
LIKE
EQ NULL
NE NULL
NOT
can be used to test for the opposite
of any condition. Parentheses ( ) can be used in the IF
clause
to denote explicitly the order of evaluation. The default order of precedence
is to evaluate expressions first, then to use the relational operators to
determine whether the test is true, then to test compound conditions.
NE
is provided as a convenient shorthand; it is identical to
NOT EQ
.
LIKE
pattern matching.)
IF
condition may consist of a number of conditions
connected by the logical operators AND, OR,
and
XOR
. AND
means both conditions must be
true; OR
means either condition must be true;
XOR
means either condition must be true but not
both.
There are numeric expressions and string expressions. Adding two numeric variables produces the sum. Concatenating two string variables produces a longer string. Numeric and string variable types cannot be mixed. There are functions to convert numbers to strings and vice versa.
Numeric expressions consist of numeric variables, constants, all of the normal arithmetic operators (+, -, /, *, **), numeric functions, and parentheses. A numeric constant starts with a number and may have a decimal point.
String expressions may use quoted strings, variables which are strings, the "+" character to join strings, string functions, and parentheses to denote the order of operation. Enclose strings in single quotes.
A function is a keyword followed by one or more arguments enclosed in
parentheses. Arguments may be variable names, constants or expressions. The
function operates on the arguments and returns an appropriate value. For
example, MOD
returns the remainder from an integer division.
The following order of precedence applies to expressions:
2*5-4 (6) 2*(5-4) (2) MOD(5,2) (remainder; 1) SALARY*52/12 (monthly salary from weekly (approx)) 'ABC' + 'DEF' ('ABCDEF') SBST('ABCDEF',4,3) ('DEF') TIMEC(NOW(0),'HH:MM:SS') (current time in display format)
IF
and
COMPUTE
. A function is a keyword followed by one or more
arguments enclosed in parentheses. Arguments may be either variable names,
constants or expressions. The function operates on the arguments and returns an
appropriate numeric (n) or string (s) value . The available functions are:
ABS
n = ABS(n)
Absolute value of n.
ACOS
n = ACOS(n) or ARCOS(n)
Arc cosine of n.
AINT
Same as
TRUNC
. Returns the integer portion of n
after truncating any fractional part.ALOG
n = ALOG(n)
Natural logarithm of n.
ALOG10
Base 10 logarithm of n.
AMOD
n = AMOD(n,m)
Remainder of integer division of n by m.
ASIN
n = ASIN(n) or ARSIN(n)
Arc sine of n.
ATAN
Arc tangent of n.
CDATE
n = CDATE (date_string,'format')
Convert a date string to a date integer using the date format specified
in quotes.
CEILING
n = CEILING(n)
The smallest integer greater than or equal to n.
CNT
The number of arguments that are not missing or undefined.
COUNT
n = COUNT(n)
The number of record type (n) in the current case.
COS
n = COS(n)
CTIME
n = CTIME (time_string,'format')
Converts a time string to a time integer using the time format specified
in quotes.
DATE
s = DATE(0)
Current date as a string in the format
MM/DD/YY
.DATEC
s = DATEC(n,'format')
Converts a date integer to a date string using the date format specified
in quotes.
DATET
The current date and time are available in a string in the format:
'
WWW,MMMDD,YYYY,HH.MMAP
' where WWW
is the
day of the week, MMM
is the first three letters of the month
name, DD
is the date, YYYY
is the year
HH.MM
is the wall clock time and AP
is AM or
PM. Select a portion of the string by specifying the beginning and ending
positions as n1 to n2. For example to return the HH.MM
(the
time in hours and minutes as a string), specify DATET(16,20)
EXISTS
n = EXISTS(expr)
Returns 0 if expression contains missing values; 1 if expression
contains a non-missing value.
EXP
n = EXP(n)
Exponentiation (base e) of n.
FIX
n = FIX(n)
Truncation of n.
FLOOR
n = FLOOR(n)
The greatest integer less than or equal to n.
FORMAT
Converts a number (n) to a string. Specify the length of string
(w) to right justify the number. If w is not specified, the number is left
justified. Specify any decimal places (d) required.
GROUP
s = GROUP(0)
Returns group name of current user.
INT
n = INT(varname)
Integer value of a categorical, date or time variable.
JULC
s = JULC(n)
Converts a date integer to a string in the format '
MMM DD,
YYYY
'.JULN
n = JULN(m, d, y)
Converts separate numeric month, day and year to a date integer.
LEN
n = LEN(s)
Length of string s.
LOG10
n = LOG10(n) or LG10(n)
Base 10 logarithm of n.
LOG
Natural logarithm of n.
LOWER
s = LOWER(s)
Convert a string to lower case.
MAX
n = MAX(n1,n2,...)
The largest value that is not missing or undefined.
MIN
n = MIN(n1,n2,...)
The smallest value that is not missing or undefined.
MOD
n = MOD(n,m)
Remainder of integer division of n by m.
NOW
n = NOW(0)
Current time as a time integer.
NUMBR
n = NUMBR(s)
Converts a string to a number.
PATTERN
n = PATTERN(s1,s2)
Returns 1 if pattern s2 is found in string s1 and 0 if not found. A
percent sign is the wildcard character. With no wildcard, an exact match is
done. For example, ('ABC','A') does not match, ('ABC','A%') does
match.
RAND
n = RAND(0) or RANF
Random uniform number between 0 and 1.
SBST
s = SBST(s,n1,n2)
Extracts a substring of string s, starting from position n1 for a
length of n2.
SIGN
n = SIGN(n1,n2)
SQRT
n = SQRT(n)
Square root of n.
SRST
n = SRST(s1,s2)
Returns the starting column in s1 of substring s2 if s2 is found
in s1 and 0 if not found. The value is positive if s2 is surrounded by special
characters or blanks; negative if s2 is surrounded by letters or numbers.
STR
s = STR(varname)
String value of a categorical, date or time variable.
SYSTEM
n = SYSTEM(n),
Returns various system status information. Set n to one of the
following codes. The value returned indicates the following meaning:
n Meaning
101 cir is new (0 no, 1 yes)
102 cir is old (0 no, 1 yes)
103 cir is changed (0 no, 1 yes)
104 cir is in process loop (0 no, 1 yes)
105 cir is marked for deletion (0 no, 1 yes)
106 record is new (0 no, 1 yes)
107 record is old (0 no, 1 yes)
108 record is changed (0 no, 1 yes)
109 record is in process loop (0 no, 1 yes)
110 record marked for deletion (0 no, 1 yes)
111 number of cases in database
112 number of record type in case
113 number of record type in database
114 current database update level
121 current mode (0 find, 1 search)
122 case lock
123 record lock
124 verify mode (0 no, 1 yes)
125 table row is new (0 no, 1 yes)
126 table row is old (0 no, 1 yes)
127 table row has changed (0 no, 1 yes)
128 table row in process loop (0 no, 1 yes)
129 t able row marked for delete (0 no, 1 yes)
130 table row is lock_type (1-6)
131 direction at field (-1 back,+1 forward)
132 direction at CIR (-1 back,+1 forward)
133 direction at record (-1 back,+1 forward)
TAN
n = TAN(n)
Trigonometric tangent of n.
TANH
n = TANH(n)
Hyperbolic tangent of n.
TIME
s = TIME(0)
TIMEC
s = TIMEC(n,'format')
Converts a time integer to a time string using the time format specified
in quotes.
TODAY
n = TODAY(0)
Current date as a date integer.
TRIM
s = TRIM(s) or TRIMR(s)
TRIML
s = TRIML(s)
Trims leading blanks of string s.
TRIMLR
s = TRIMLR(s) or TRIMRL(s)
Trims leading and trailing blanks of string s.
TRUNC
Same as
AINT
. Returns the integer portion of n
after truncating any fractional part.UPPER
s = UPPER(s)
Converts string s to upper case.
USER
s = USER(0)
Returns current user name.