How to restructure data in SPSS Modeler

106 views Asked by At

May I know how I can convert the data in SPSS Modeler as the image below?

enter image description here

I have read How to restructure data in SPSS Modeler? and tried Restructure but it did not generate format like "From_1", "To_1", etc.

Greatly appreciate any help/advice. Thanks a lot in advance.

1

There are 1 answers

2
eli-k On BEST ANSWER

The following syntax will work in SPSS:

(this part is just to reconstruct your example)

data list list/ID (F3) Date (Edate8) xfrom xto (2A3).
begin data
    881    01/01/22    "abc"    "def"
    881    02/01/22    "dfd"    "gdk"
    883    10/01/22    "gbd"    "kiu"
    883    14/01/22    "hdd"    "kkh"
end data.

Now for the restructure - before you can use casestovars for restructure, you need an index of cases in each ID:

sort cases by ID Date.
compute ind=1.
if $casenum>1 and ID=lag(ID) ind=lag(ind)+1.
exe.
formats ind (f1).
casestovars /id=ID/index=ind/separator="_".