Adding same data for same value of variable(i.e ID)

女生的网名这么多〃 提交于 2021-01-28 04:52:28

问题


I have two sets of data files in .sav (EMR.sav and APP.sav)

What I want to do, it merge the two data of EMR and APP, to do "comparison of steps by sex".

The data of EMR is as follows:

pid sex
306 1
866 1
896 1
921 2

The data of APP would be something like this(the A_id would equal to pid in EMR):

A_id A_calorie A_distance
866   124        14
866   24         24
866   13         35
866   12         23
866   23         0
921   101        23
921   12         13
921   19         24
921   200        235 
921   232        241

The result I want to get is the two data files to merge and have:

pid  sex   A_calorie A_distance
866   1       124        14
866   1       24         24
866   1       13         35
866   1       12         23
866   1       23         0
921   2       101        23
921   2       12         13
921   2       19         24
921   2       200        235 
921   2       232        241

But, what I keep getting is

pid  sex   A_calorie A_distance
866   1       124        14
866   .       24         24
866   .       13         35
866   .       12         23
866   .       23         0
921   2       101        23
921   .       12         13
921   .       19         24
921   .       200        235 
921   .       232        241

How can I get all the same pid have the same sex value??

By the way, if it was R, one would use something like merge(EMR, APP, key=pid)


回答1:


You can sort the files and use match files to get what you need:

get file=" ...... EMR ...... ".
sort cases by pid.
dataset name EMR.

get file=" ...... APP ...... ".
dataset name APP.
sort cases by A_id.
match files /file=* /rename A_id=pid /table=EMR /by pid.
exe.


来源:https://stackoverflow.com/questions/65192821/adding-same-data-for-same-value-of-variablei-e-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!