14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

198 Programming Methods Chapter 8<br />

Advanced Scoping and Namespaces<br />

Table 8.4 Functions for manipulating lists or expressions (Continued)<br />

Function Syntax Explanation<br />

Substitut<br />

e<br />

Substitut<br />

e Into<br />

R =<br />

Substitute(list|exp<br />

r, Expr(pattern),<br />

Expr(replacement),<br />

...)<br />

Substitute<br />

Into(list|expr,<br />

Expr(pattern),<br />

Expr(replacement),<br />

...)<br />

Finds all matches to the pattern in the list or expression, and<br />

replaces them with the replacement expression. Each pattern<br />

must be a name. The second and third arguments are<br />

evaluated before they are applied, so most of the time you<br />

must quote them with an Expr function. To delay evaluating<br />

an argument, use Name Expr instead of Expr. You can list<br />

multiple pattern-replacement pairs for multiple substitutions<br />

in one statement.<br />

Substitute in place.<br />

Advanced Scoping and Namespaces<br />

Scripts that are used in production environments need to use more advanced scoping techniques to avoid<br />

collisions between scripts. JMP provides three progressively more advanced techniques:<br />

• The Names Default To Here() function. If you have simple scripting needs, this single command<br />

might be sufficient. See “Names Default To Here” on page 198.<br />

• Scopes that are pre-defined by JMP. See “Scoped Names” on page 201.<br />

• Namespaces that you can create for your scripts. See “Namespaces” on page 204.<br />

Names Default To Here<br />

If you write production scripts, you need to insulate the script from the current user environment.<br />

Otherwise, the variables that you use might interact with variables used by the user and by other scripts. The<br />

way to do this is to keep your names in a local environment, which you can do by setting an execution mode<br />

with the statement:<br />

Names Default To Here(1);<br />

Unqualified names in a script with the Names Default To Here mode turned on are private to that script.<br />

However, the names persist as long as the script persists, or as long as objects created by or holding the script<br />

are still active. We recommend that all production scripts start with Names Default To Here(1) unless<br />

there is a specific reason not to do so. When the script uses an unqualified name in this mode, that name is<br />

resolved in the local namespace.<br />

To refer to global variables, scope the name specifically as a global variable (for example, ::global_name).<br />

To refer to columns in a data table, scope with name specifically as a data table column (for example,<br />

:column_name).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!