UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

NOTE: This page has been delinked.  It is no longer being maintained, and information on this page may be out of date.

SPSS FAQ
Reshaping a file from wide to long

This page is adapted from the SPSS AnswerNet.  We are grateful to SPSS for permission to use provide their information to adapt and distribute this page from our web site.

Q.
My data file has a single record per case and several variables that indicate measurements of the same variable at different times. I would like to have a record in my data set for each measurement taken. In short, I want to go from a single record per case to multiple records per case.

A.
The following syntax example does the restructuring that you require with a single variable. Included within this sample syntax is out put from the LIST command. This output shows you how the file is being changed at specific steps in the process. If you run this syntax example on your own, please omit the output that is included here.

* To make many from one *.
DATA LIST / ID Y_1 TO Y_5 (6(F1.0,1x)).
BEGIN DATA
1 3 4 5 6 3
2 5 5 7 1
END DATA.
LIST.
ID Y_1 Y_2 Y_3 Y_4 Y_5
1.00 3.00 4.00 5.00 6.00 3.00
2.00 5.00 5.00 7.00 1.00 .
VECTOR Y_=Y_1 TO Y_5.
LOOP REC=1 TO 5.
COMPUTE Y=Y_(REC).
XSAVE OUTFILE 'TMP' / KEEP ID REC Y.
END LOOP.
EXE.
GET FILE 'TMP'.
LIST.
ID REC Y
1 1.00 3.00
1 2.00 4.00
1 3.00 5.00
1 4.00 6.00
1 5.00 3.00
2 1.00 5.00
2 2.00 5.00
2 3.00 7.00
2 4.00 1.00
2 5.00 .

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.