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.

200 Programming Methods Chapter 8<br />

Advanced Scoping and Namespaces<br />

Note that if you use ::a instead of global:a in the Show() function, your output is a little different:<br />

show(::a, a, here:a);<br />

a = 1;<br />

a = 5;<br />

here:a = 5;<br />

Example of Using the Names Default To Here() Function<br />

You have two scripts with the following definitions, and Names Default To Here() is turned off (the<br />

default condition) in both scripts.<br />

Note: Both scripts must be in separate script windows for this example.<br />

// Script 1<br />

a = 1;<br />

show(a);<br />

// Script 2<br />

a = 3;<br />

show(a);<br />

1. Run Script 1. The result is as follows:<br />

a = 1<br />

2. Run Script 2. The result is as follows:<br />

a = 3<br />

3. Run only the show(a); line in Script 1. The result is as follows:<br />

a = 3<br />

The log shows a = 3 because variable a is global, and was last modified by Script 2. This is the default<br />

behavior in JMP 9 and later, and it is the only possible behavior in JMP 8 and earlier.<br />

4. Now turn on Names Default To Here() in both scripts.<br />

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

Note: Names Default To Here() is local to a particular script. It is not a global setting.<br />

5. Run Script 1. The result is as follows:<br />

a = 1<br />

6. Run Script 2. The result is as follows:<br />

a = 3<br />

7. Run only the show(a); line in Script 1. The result is as follows:<br />

a = 1<br />

The log shows a = 1, because a copy of variable a is maintained for each script.

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

Saved successfully!

Ooh no, something went wrong!