SPSS VarsToCases
The VARSTOCASES command translates a wide dataset into long format. See also CASESTOVARS.
Contents
Usage
varstocases /make Sales from Sales.1 to Sales.4.
For each variable listed after FROM, a new row of data is created with that variable's value set instead into the /MAKE variable. All other variables are duplicated for each created row of data.
Id
The /ID subcommand creates a numeric variable storing the $casenum on the original, wide dataset. If the dataset already has an ID variable, it will automatically be duplicated to each created row of data, and the /ID subcommand won't offer any significant advantage over this.
Index
The /INDEX subcommand creates an index variable marking a created row's sequence within its group. This index variable will have an F8.0 format.
varstocases /make Sales from Sales.1 to Sales.4 /index=fiscalquarter.
To create an index variable that instead stores the string name of the source variable variable, try:
varstocases /make Sales from Sales.1 to Sales.4 /index=fiscalquarter (Sales).
Null
By default, SPSS will not create a row for missing values found on the /MAKE subcommand's FROM list. Add the /NULL=DROP subcommand to explicitly allow this behavior, or add the /NULL=KEEP subcommand to disable it.
Data Model
The VARSTOCASES command recognizes SPLIT FILE and WEIGHT statuses and preserves them, unless the relevant variables are used on a /DROP or /MAKE subcommand.
The VARSTOCASES command does not recognize FILTER status.