Chapter Contents |
Previous |
Next |
REPLACE |
Category: | Submit Block |
Syntax | |
Details | |
Example |
Syntax |
REPLACE variable replacement-string; |
Type: Character
Type: Character
Details |
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'; else 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 rules:
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.
Example |
replace tablename 'data=&tablename'; ...more SCL statements... submit continue; proc print &tablename; run; endsubmit;
If TABLENAME contains '
'
(or _BLANK_), the submitted statements are
submit continue; proc print; run; endsubmit;However, if TABLENAME contains
work.sample
, the submitted
statements are
submit continue; proc print data=work.sample; run; endsubmit;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.