In SPSS, how can I restructure data using Syntax commands?

SPSS allows you to use Syntax code to reshape data from wide to long format, and vice versa. Below are data sets repeatedly measured in wide and long format. Note that the example data contain two participants measured on two outcome variables (weight and calories), under three different time points.

The wide format uses one row for each observation or participant:

  ID    WEIGHT1   WEIGHT2    WEIGHT3    CALORIE1    CALORIE2    CALORIES3
   1      200       190        180         3500         3300         3100
   2      160       150        140         3000         2900         2800

The long format uses multiple rows for each observation or participant:

  ID   WEIGHT   CALORIES  TIME
   1     200     3500      1 
   1     190     3300      2
   1     180     3100      3
   2     160     3000      1
   2     150     2900      2
   2     140     2800      3

To restructure data from wide to long, use the VARSTOCASES command:

    VARSTOCASES
   /make WEIGHT from WEIGHT1 WEIGHT2 WEIGHT3 
   /make CALORIES from CALORIES1 CALORIES2 CALORIES3
   /index= TIME(3)
   /keep=ID.

To restructure data from long to wide, use the CASESTOVARS command:

     CASETOVARS
     /id=ID
     /index = TIME. 
 

Alternatively, you can use the Data Restructuring Wizard in SPSS; for more, see In SPSS, how can I restructure data?

If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200; staff are available for consultation Monday-Friday 9am-noon and by appointment.

This is document bclg in the Knowledge Base.
Last modified on 2015-07-06 00:00:00.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.