|SAS Component Language Dictionary
Substitutes a replacement string for a reference to an SCL variable
in the SUBMIT block
REPLACE variable replacement-string;
is the variable whose value the replacement
value is substituted for.
is the text to substitute for the variable's
value. This text can include a variable's value, but that is not mandatory.
REPLACE substitutes a replacement string for a reference
to an SCL variable in the SUBMIT block only if the variable is not blank.
It functions as an implicit IF statement, determining when to substitute the
string in the SUBMIT block. Using the REPLACE statement reduces the amount
of code needed to generate statements to be submitted.
The REPLACE statement is evaluated when the program
is compiled. Different replacement strings cannot be substituted based on
conditions that exist at execution time. For example, the following statements
cause errors when you compile the program:
if (x) then
replace y '&y';
replace y '&z';
If you use multiple REPLACE statements for the same
variable, the last REPLACE statement is used and a warning is generated by
the compiler to that effect.
A good programming practice is to collect all the REPLACE
statements in one place in your SCL program.
You can also use the REPLACE option in the ATTR window
of a PROGRAM entry to specify the replacement string. However, this can be
overridden by REPLACE statements in the SCL program.
SCL performs substitution according to the following
If the value of the SCL variable is blank (or
_BLANK_), no substitution is performed.
If the value of the SCL variable is not blank,
SCL performs substitution into the replacement string for the variable and
substitutes the resulting string into the SUBMIT block.
The replacement string can reference other SCL variables.
Note: Replacement strings are not recursive. When you refer
to another variable in the replacement string, the program uses the current
value of the variable, not the value that is based on its replacement string.
replace tablename 'data=&tablename';
...more SCL statements...
proc print &tablename;
If TABLENAME contains '
'(or _BLANK_), the submitted statements are
However, if TABLENAME contains work.sample
, the submitted
proc print data=work.sample;
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.