14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 JSL Building Blocks 79<br />

Global and Local Variables<br />

Table 5.3 Operators and Their Function Equivalents in Order of Precedence (Continued)<br />

Operator Function Syntax Explanation<br />

+= Add To a+=b<br />

AddTo(a,b)<br />

–= Subtract To a–=b<br />

SubtractTo(a,b)<br />

*= Multiply To a*=b<br />

MultiplyTo(a,b)<br />

/= Divide To a/=b<br />

DivideTo(a,b)<br />

; Glue a;b<br />

Glue(expr, expr, ...)<br />

Add the value of b into a.<br />

Subtract b from a, and put back into a.<br />

Multiply b with a, and put back into a.<br />

Divide b into a, and put back into a.<br />

First do a, and then do b.<br />

Global and Local Variables<br />

Variables are names that hold values, which you reference later in scripts. There are two types of variables:<br />

• Global variables are shared among all scripts that you run in a JMP session.<br />

• Local variables apply only to the script context in which you define them. They can also be local to only<br />

a piece of a script, as with variables local to a particular function.<br />

To limit the scope of variables, you can define them in a namespace, which is a collection of variables,<br />

functions, and other unique names. JMP has a single global variable namespace that all scripts use by<br />

default. When you use a name plainly, without a qualifying syntax, the name is an unscoped variable and<br />

therefore in the global namespace.<br />

x = 1;<br />

Putting variables in the global namespace can cause conflicts. When two scripts have variables with the same<br />

names, the value of the variable in the last script that you run last overwrites the variable’s value in the first<br />

script.<br />

To prevent this problem, we recommend that you begin each script with the following line:<br />

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

The Names Default To Here(1); function makes all unscoped variables in the script local to that script<br />

and does not affect the global variable namespace. “Advanced Scoping and Namespaces” on page 198<br />

provides more details.<br />

You can also create a variable in a specific namespace. In the following example, the x variable is created in<br />

the aa namespace:<br />

aa:x = 1;

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

Saved successfully!

Ooh no, something went wrong!