根据键ID将行更改为列

时间:2018-09-06 12:31:01

标签: spss

因此,这是我所拥有的示例,并说明了我要寻找的内容。我似乎无法使SPSS中的重组功能正常工作,这可能是工作的错误工具。任何帮助,将不胜感激。谢谢!

  • ID | Car_Make | Car_Model
  • 999,斯巴鲁,WRX
  • 867,沃尔沃,240
  • 999,Ac歌,TSX

  • ID | Car_Make1 | Car_Model1 | Car_Make2 | Car_Model2 .....(取决于列表)
  • 999,斯巴鲁,WRX,Ac歌,TSX
  • 867,沃尔沃,240

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

What you are missing is a key\index variable. Try this:

* first recreating your sample data.
data list list/ ID (f10) Car_Make  Car_Model (2a20).
begin data
999, "Subaru", "WRX"
867, "Volvo", "240"
999,"Acura", "TSX"
end data.

* now creating an index and restructuring.
sort cases by ID.
compute ind=1.
format ind(f2).
if $casenum>1 and ID=lag(ID) ind=lag(ind)+1.
casestovars /id=ID/index=ind/sep="_".