merging files

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

merging files

taelee
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
Reply | Threaded
Open this post in threaded view
|

Re: merging files

Bruce Weaver
Administrator
See the intermediate data management tutorials here:

  http://www.ats.ucla.edu/stat/spss/topics/data_management.htm


taelee wrote
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: merging files

Albert-Jan Roskam
In reply to this post by taelee
_______________________________

> 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