
SPSS VARSTOCASES is short for “variables to cases”. It restructures data by stacking variables on top of each other as illustrated by the figure above. You can try this simple example for yourself by downloading and opening sav_data018 and running the syntax below on it.
SPSS VARSTOCASES Example 1
varstocases
/make v from v1 v2
/index q (v).
SPSS VARSTOCASES - Why?
One good reason for using VARSTOCASES is that many SPSS graphs can only be generated after stacking the relevant variables on top of each other. On top of that, VARSTOCASES also facilitates generating some tables. For example, let's take a look at some of the data in freelancers.sav.

We may want to compare the sectors our respondents have been working in over years as in the table below.

Makes sense, right? Now, one way for creating this table is CTABLES (custom tables) but this requires a (paid) add-on module. Second, TABLES will do the trick but it's available only in (challenging) syntax and no longer documented.
The third option is VARSTOCASES followed by CROSSTABS as demonstrated below. Note that VARSTOCASES results in an incorrect variable label so we correct that in step 2. We'll discuss this problem a bit later on.
SPSS VARSTOCASES Example 2
varstocases
/make sector from sector_2010 to sector_2014
/index year(sector).
*2. Correct variable label.
variable labels sector "Sector in which respondent was working".
*3. Extract year from string.
compute year = char.substr(year,index(year,'_') + 1).
execute.
*4. Generate table.
crosstabs sector by year/cells column.
SPSS VARSTOCASES - Creating Multiple Variables
Our first two examples created one variable holding the original values and a second (index) variable holding the original variable names. In some cases, however, you may want to restructure multiple sets of variables in one go. For instance, let's consider sav_data016, holding typical reaction time data.

Apparently, respondents took 5 trials, each resulting in an answer and a reaction time. So do wrong answers have shorter or longer average reaction times? One way to figure out is using the VARSTOCASES syntax below, perhaps followed by MEANS.
SPSS VARSTOCASES Example 3
varstocases
/make t from t1 to t5
/make a from a1 to a5
/index trial.
Result

SPSS VARSTOCASES - Wrong Results
In our second example, we placed two variables on top of each other in one new variable. Both input variables had a variable label but the (single) output variable can have only one variable label. SPSS “solves” the problem by using the first variable label it encounters. In most cases, this will be incorrect but we'll readily see the problem.
The real problem with VARSTOCASES is that the same principle holds for value labels. This may result in nonsensical results. We'll now demonstrate this on sav_data017, part of which are shown below.

We first run basic FREQUENCIES. Note that both questions basically indicate that politicians are not very popular with our respondents.
set tnumbers both.
*2. Frequency tables.
frequencies v1 v2.
Result

Importantly, these tables also show that our two variables have inconsistent value labels. We now run VARSTOCASES and replicate both frequency tables with a single contingency table.
SPSS VARSTOCASES Example 4
varstocases
/make v from v1 v2
/index question(v).
*2. Remove incorrect variable label.
variable labels v ''.
*3. Note that result is not correct.
crosstabs v by question/cells columns.
Result

Note that VARSTOCASES has applied the value labels of v1 to the values of v1 and v2, resulting in misleading results. Even more disturbing, SPSS didn't throw any error or warning that things were going wrong at some point.
Believe it or not but this is not a bug. VARSTOCASES is supposed to work like this and this behavior is described in the CSR. We wonder, however, how many SPSS users are aware that this may happen. And even those who are aware have no efficient way for circumventing it as SPSS completely lacks any dictionary consistency check.
On a personal note, we feel that VARSTOCASES should perform such a check by default and at least issue a warning if things do go wrong. This suggestion goes for ADD FILES too, which shows similar problematic behavior which is even harder to avoid.
THIS TUTORIAL HAS 9 COMMENTS:
By Jon Peck on May 5th, 2016
Users of VARSTOCASES might like to know that the companion command CASESTOVARS exists.
As for label checking, that's a good idea as long as it is permissive, i.e., only actual conflicts would trigger it. Just having a label on one value or variable that isn't present in others shouldn't be an error.
By Ruben Geert van den Berg on May 6th, 2016
Hi Jon! Thanks for your feedback!
I might indeed mention CASESTOVARS. I don't have a lot of real life examples where it really solves any problems but if others do, I'll happily write something about that as well.
Perhaps conflicting dictionaries should trigger a warning instead of an error, even when values don't actually occur in the data. Because if they don't, they could be created after VARSTOCASES with an IF or RECODE command and that would result in incorrect conclusions anyway.
The problem with different VALUE LABELS schemes could be circumvented with a brute force approach: convert all variables to strings with the VALUELABELS function, then run VARSTOCASES, and then AUTORECODE the result. However, AUTORECODE often results in the "wrong" (alphabetical) order for Likert type responses such as "Bad", "Good", "Neutral" and so on.
IMHO, it's a pity that AUTORECODE can't look up and reorder the value labels as in the Chart Builder dialogs. By default, the Chart Builder will often include all values that are labelled, even if absent from the data. I very much appreciate this feature (and so do my clients). It often keeps charts' legends consistent over charts on separate variables.
By Jon Peck on May 6th, 2016
I think CASESTOVARS actually gets more use than the other way. It is mainly needed to prepare data for thoe procedures that require wide rather than long data.
I was agreeing with you that there should be a warning for inconsistent labelling. You can, if desired, use APPLY DICTIONARY to copy the value labels and other properties from one variable to another.
As for AUTORECODE, look at the template capabilities. You could set a template, call it Likert, t define the desired order and just use it as input to AUTORECODE.
By Ruben Geert van den Berg on May 7th, 2016
Hi Jon, thanks for your feedback! I'm sure I could figure things out with an AUTORECODE template but I'm afraid the average SPSS user will find it rather intimidating.
Please don't take this the wrong way but I think that a sole APPLY DICTIONARY command is not a good idea for this situation. If 0 = female and 1 = male, then changing these value labels (with APPLY DICTIONARY or otherwise) will only result in correct results if accompanied by a corresponding RECODE command.
By Jon Peck on May 7th, 2016
The AUTORECODE template use case was for database access where new values might show up but you want to retain the existing autorecode for previous values, but it would actually work well for the Likert example. You take a variable that is properly coded and run AUTORECODE on it saving a template. Then you just use that template for future recodes. And autorecode will fix the value labels at the same time.