_______________________________
> From: taelee <
[hidden email]>
>To:
[hidden email]
>Sent: Thursday, February 21, 2013 10:20 PM
>Subject: [SPSSX-L] merging files
>
>Hello,
>I'm trying to merge two files (A and B). File A has 5000 cases (id, v1, v2)
>and File B has 4000 cases (id, v2, v3, v4). Is there a way to merge these
>two files so that it has all 5000 cases with id, v1-v4? Thank you in
>advance.
>Tae
Hi,
Are the IDs unique? If so:
FILE HANDLE path /NAME = 'c:/your/path/here'.
FILE HANDLE file_a / NAME = 'path/file_a.sav'.
FILE HANDLE file_b / NAME = 'path/file_b.sav'.
GET FILE = file_a.
SORT CASES BY id.
DATASET NAME a.
GET FILE = file_b.
SORT CASES BY id.
MATCH FILES / FILE = a / IN = in_file_a / FILE = * / BY = id.
EXECUTE.
If either a, or b has non-unique ids, specify 'TABLE =' instead of ' FILE = ' for the file with non-unique IDs.
If both IDs are non-unique, you could use AGGREGATE, LAG, or CASESTOVARS to make the id unique.
Or you could make a many-to-many match, which is not possible out of the box. It's possible with syntax, but I'd use a cross join after loading the files into a database. Or use R.
=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD