Monday 8 January 2007

Temporary variable SCRATCH

Any variable name that begins with a pound sign (#) is treated as a scratch variable that is discardd at the end of the series of transformation commands.
Simple sample:

[Syntax]
DATA LIST FREE /var1.
BEGIN DATA
1 2 3 4 5 6
END DATA.
COMPUTE factor=1.
LOOP #tempvar=1 TO var1.
- COMPUTE factor=factor * #tempvar.
END LOOP.
EXECUTE.
[/Syntax]

The scratch variable #tempvar is used as an index variable for the loop structure. For each case, the COMPUTE command is run iteratively up to the value of var1. For each iteration the current value of the variable factor is multiplied by the current loop iteration number stored in #tempvar.

Result will be:
1 1
2 2
3 6
4 24
5 120
6 720

2 comments:

ugg boots günstig said...

I hope this allowed, I have never used this website before so I wasn’t really sure what this was going to do. spss So this is just a test post. I really like this forum, it has some excellent discussions that take place.

Unknown said...

Hi,
I have the following question: I have my data which looks like this:
UserId |Act1 |Act2 |Act3 |Act4
1 | 2 | 3 | 2 | 2
1 | 2 | 5 | 1 | 0
1 | 0 | 3 | 3 | 0
2 | 2 | 2 | 3 | 0
2 | 2 | 2 | 2 | 2
2 | 1 | 2 | 1 | 5
...
999 | 1 | 2 | 2 | 3
I want to rank every case and create a variable “Strategy”. If Act1 is the highest score between Act1-Act4 then Strategy should be equal to "1". If Act2 is higher, then Strategy should be equal to "2". I have the same UserId's since I have made repeated measuring of the same variable (in this example 3 times).
How should the SPSS Syntax Code look like? Can I make a loop to go through every variable to define a strategy that my users used in the experiment on this turn? Could you give me an advice?

Thanks,
Best,
Eugene (eugenleo(at)gmail.com)