SAS Component Language: Reference |
In interactive
applications, values for statements in a submit
block may need to be determined by user input or program input in the application.
An SCL feature that supports this requirement is the substitution of text
in submit blocks, based on the values of fields or SCL variables.
|
How Values Are Substituted in Submit Blocks |
SCL performs substitution in submit blocks according
to the following rules:
- When SCL encounters a name that is prefixed with
an ampersand (&) in a submit block, it checks to see whether that name
is the name of an SCL variable. If it is, then SCL substitutes the value of
that variable for the variable reference in the submit block. For example,
suppose a submit block contains the following statement:
proc print data=&table;
If the application includes a variable named TABLE whose
value is work.sample
, then this statement is
passed to the preview buffer:
proc print data=work.sample;
- If the name that follows the ampersand does not
match an SCL variable, then no substitution occurs. The name is passed unchanged
(including the ampersand) with the submitted statements. When SAS software
processes the statements, it attempts to resolve the name as a macro variable
reference. SCL does not resolve macro variable references within submit blocks.
For example, suppose a submit block contains the following statement:
proc print data=&table;
If there is no SCL variable named TABLE in the application,
then the statement is passed unchanged to the preview buffer. SAS software
attempts to resolve &TABLE as a macro reference when the statements are
processed.
- CAUTION:
- Avoid using the same name for both an
SCL variable and a macro variable that you want to use in submitted statements.
SCL substitutes the value of the corresponding
SCL variable for any name that begins with an ampersand. To guarantee that
a name is passed as a macro variable reference in submitted statements, precede
the name with two ampersands (for example, &&TABLE).
|
Specifying Text for Substitutions |
If an SCL variable that is used in a substitution contains
a null value, then a blank is substituted for the reference in the submitted
statements. This can cause problems if the substitution occurs in a statement
that requires a value, so SCL allows you to define a replacement string for
the variable. If the variable's value is not blank, the complete replacement
string is substituted for the variable reference. To define a replacement
string, you can use either the Replace attribute (for a control or field)
or the REPLACE statement.
Using the REPLACE Statement
The REPLACE statement acts as an implicit
IF-THEN statement that
determines when to substitute a specified string in the submit block. Consider
the following example:
replace table 'data=&table';
...more SCL statements...
submit;
proc print &table;
run;
endsubmit;
If the SCL variable TABLE contains
' '
(or _BLANK_
),
then these statements are submitted:
proc print;
run;
If the SCL variable TABLE contains work.sample
, then these statements are submitted:
proc print data=work.sample;
run;
Using the Replace Attribute
In SAS/AF applications, you can also can
define replacement strings
for a window variable using the Replace attribute in the properties window
(for a control) or the attribute window (for a field). The text that you specify
for the Replace attribute is substituted for the variable name when the variable
name is preceded with an ampersand in submitted statements.
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.