SAS Component Language: Reference |
SCL supports the syntax of the SAS
DATA step with the exceptions
and additions noted. Refer to SAS Language Reference: Dictionary for details about the SAS language
elements that are available in the DATA step.
SCL does not support the DATA step statements that relate
specifically to creating SAS data tables, such as the DATA, SET, INFILE, and
DATALINES statements. However, SCL does provide special functions that can
perform equivalent SAS table manipulations. See Using SAS Tables
for details.
SCL Language Elements by Category lists the statements
that are supported by SCL and tells you where they are documented. The ARRAY,
DO, LENGTH, PUT, and SELECT statements are different in SCL. The differences
are documented in their entries in SAS Component Language Dictionary. The following list shows the DATA step
statements that are valid in SCL programs and notes differences between a
statement's support in SCL and in the DATA step.
- ARRAY (Explicit)
- defines the elements of an explicit array.
_NUMERIC_, _CHARACTER_, and _ALL_ are not supported.
- assignment
- assigns values to variables.
- comment
- documents the purpose of a program.
- CONTINUE
- stops the processing of the current DO loop
and resumes with the next iteration of that DO loop. See the dictionary entries
for DO as well as CONTINUE for information about the differences in the behavior
of this statement in SCL.
- DO, iterative DO, DO-UNTIL, DO-WHILE
- repetitively execute one or more statements.
SCL does not support the DO-list form of the DO statement, but it does support
LEAVE and CONTINUE statements that extend the capabilities of DO-group processing.
- END
- designates the end of a DO group or SELECT
group.
- GOTO
- jumps to a specified program label.
- IF-THEN-ELSE
- enables conditional execution of one or
more statements.
- %INCLUDE
- accesses statements (usually from an external
file) and adds them to the program when the SCL program compiles.
- LEAVE
- stops executing the current DO group and
resumes with the next sequential statement. See the dictionary entries for
DO as well as LEAVE for information about the differences in the behavior
of this statement in SCL.
- LENGTH
- allocates storage space for character and
numeric variables. In SCL, the LENGTH statement can set only the lengths of
nonwindow variables.
- LINK
- jumps to a specified program label but allows
a return to the following statement. SCL allows nesting of up to 25 LINK statements.
- NULL
- is an executable statement that contains
a semicolon (;) and acts as a place holder.
- PUT
- writes text to the LOG window.
- RETURN
- returns control or a value to the calling
routine or application. In SCL, RETURN can also return a value from the execution
of a method.
- RUN
- is an alias for the RETURN statement.
- SELECT-WHEN
- enables conditional execution of one or
several statements or groups of statements.
- STOP
- is an alias for the RETURN statement.
- SUM
- adds the result of an expression to an accumulator
variable.
SCL supports all DATA step functions except LAG and DIF. See SCL Elements by Category for a list of the DATA
step functions that are supported by SCL. See SAS Language Reference: Dictionary for details about other
DATA step functions that are supported by SCL.
Variables in SCL programs share most of the characteristics of variables in
the DATA step such as default length and type. However, you should be aware
of the differences described in the following sections. In addition, SCL variables
can be declared to be local in scope to a DO or SELECT block.
Numeric Variables
A variable is assigned the numeric data type if its data type
is not explicitly declared.
Character Variables
In SCL, the length of a character variable is determined as
follows:
- For window variables, the maximum length of a
variable is equal to the length of the corresponding control or field in the
window.
- For character-type nonwindow variables, the length
is 200 characters unless a different length is explicitly declared. However,
you can use the DECLARE or LENGTH statement to change the length from a minimum
of 1 character to a maximum of 32K characters. The maximum length of a nonwindow
variable is not affected by the length of a string that is assigned to the
variable in the SCL program. For example, suppose your SCL program contains
the following statement and that the window for the application does not include
a field named LongWord:
LongWord='Thisisaverylongword';
As
a result of this assignment statement, SCL creates a nonwindow variable named
LongWord with a maximum length of 200 characters. The length of the string
in the assignment statement has no effect on the maximum length of the variable.
By contrast, this same assignment in a DATA step would create a variable
with a maximum length of 19 characters.
As in the DATA step, the LENGTH function in SCL returns
the current trimmed length of a string (the position of the nonblank character
at the right end of the variable value). However, SCL also provides the MLENGTH
function, which returns the maximum length of a character variable, as well
as the LENGTH function with the NOTRIM option, which returns the untrimmed
length of a string.
SCL supports the standard DATA step expressions in an identical manner. The
only exception is the IN operator, which has the following syntax:
i=variable IN
(list-of-values)|array-name;
|
In SCL, the IN operator returns the index of the element
if a match is found, or it returns 0 if no match is found. However, in the
DATA step, the IN operator returns 1 if a match is found and 0 if no match
is found. The IN operator is valid for both numeric and character lists as
well as for arrays. If a list that is used with the IN operator contains values
with mixed data types, then those values are converted to the data type of
the first value in the list when the program is compiled.
In the following example, the statements using the IN
operator are equivalent:
array list{3}$ ('cat','bird','dog');
i='dog' in ('cat','bird','dog');
i='dog' in list;
In SCL, this example produces I=3, whereas in the DATA
step the example produces I=1. Also, the DATA step does not support the form
i='dog' in list
.
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.