1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
*(Q) How to have a "global variable".
>What I want to do is have some variable, say MYNUMBER, that I change within
>the syntax.  What I want is to say at the beginning of the syntax that
>MYNUMBER=83, and then throughout the rest of the syntax, refer to only
>MYNUMBER (but meaning 83).  And in the future, if I want to change MYNUMBER
>to, say, 104, I can do it just once at the beginning of the syntax, because
>everywhere else in the syntax where I need the variable

*(A) Posted to SPSS newsgroup on 2002/03/25 by Raynald Levesque.
* The best method is to use a macro.

* For instance.
DEFINE mynumber()83!ENDDEFINE.

GET FILE='c:\\program files\\spss\\employee data.sav'.
COMPUTE sal=salary*mynumber.

*************.
* Additional comments:

Using a temporary variable such as 
COMPUTE #mynumb=83.
does not work because temporary variables cease to 
exist as soon as a procedure or an EXECUTE is encountered.

Using a regular variable
COMPUTE mynumber=83.
works only with the current data file. If you load a new 
sav file you loose your variable. There are ways to keep it by 
saving it in a file and merging that file with the new data file 
but this is much more cumbersome than using a macro.