Search code examples
spss

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


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)


Solution

  • 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.