Size: 648
Comment:
|
← Revision 3 as of 2023-06-09 16:38:07 ⇥
Size: 729
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
A '''scratch variable''' is a temporary variable that is not initialized between cases. As a program iterates over each row of data, scratch variables retain their value. |
|
Line 11: | Line 13: |
Scratch variables are declared like: | Scratch variables are declared with a hash (`#`) prefix. Try: |
Line 16: | Line 18: |
Note the names are prefixed with a hash (`#`). This is a requirement. |
|
Line 25: | Line 25: |
Scratch variables are firstly useful as temporary variables. They are deleted in the next execution (e.g. the next `EXECUTE` command). | Scratch variables are firstly useful as temporary variables. They are automatically deleted in the next [[SPSS/Execute|execution]]. |
Line 27: | Line 27: |
Scratch variables are also useful for data aggregation, as they are not re-initialized for each case. | Scratch variables can also be used to aggregate data. |
Line 33: | Line 33: |
SPSS Scratch Variables
A scratch variable is a temporary variable that is not initialized between cases. As a program iterates over each row of data, scratch variables retain their value.
Contents
Declaration
Scratch variables are declared with a hash (#) prefix. Try:
compute #TotalSales = sum(Sales, #TotalSales).
Usage
Scratch variables are firstly useful as temporary variables. They are automatically deleted in the next execution.
Scratch variables can also be used to aggregate data.
compute #TotalSales = sum(Sales, #TotalSales). compute Total_Sales = #TotalSales.