merging two databases

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

merging two databases

Miriam Haverkamp-2
Hello,
I would like to merge two databases that have the same IDs. One database has about several rows with the same ID which gives me the error message as there is no unique identifier. I do not care it could just fill in the data in duplicate for the same ID. Anyway I can get SPSS to match it with the first observation with that ID?
 
Thanks!
 
Miriam
Reply | Threaded
Open this post in threaded view
|

Re: merging two databases

Maguin, Eugene
Miriam,

Your message is kind of confusing with respect to the outcome you want or
will accept. So, I'll describe a couple of possibilities and you can choose.
You have two databases, one with multiple rows per Id, call this one DB1,
and another with one row per id, call this one DB2.

One thing you can do is to substitute the table keyword for one of the file
keywords. Like this.

Match files file=db1/table=db2/by id.
Execute.

What you are going to get is that the data for an id in DB2 is added to
every case in db1 with the same id. This fits with this part of your
message: 'I do not care it could just fill in the data in duplicate for the
same ID.' You'll definitely get that.


But maybe you don't like that, really. So create a row or record identifier
in both db1 and db2 and then use match files. Like this.

*  in db2. Only one record per case. Exploit this.
Get file=db2.
Compute rec=1.
Execute.
Save outfile=db2a.

*  in db1. multiple records per case.
Get file=db1.
Compute rec=1.
If (id eq lag(id)) rec=lag(rec)+1.
Execute.
Save outfile=db1a.

Match files file=db1a/file=db2a/by id rec.
Execute.


Gene Maguin


>>I would like to merge two databases that have the same IDs. One database
has about several rows with the same ID which gives me the error message as
there is no unique identifier. I do not care it could just fill in the data
in duplicate for the same ID. Anyway I can get SPSS to match it with the
first observation with that ID?

Thanks!

Miriam

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

Re: merging two databases

Bruce Weaver
Administrator
In reply to this post by Miriam Haverkamp-2
Miriam Haverkamp-2 wrote
Hello,
I would like to merge two databases that have the same IDs. One database has
about several rows with the same ID which gives me the error message as
there is no unique identifier. I do not care it could just fill in the data
in duplicate for the same ID. Anyway I can get SPSS to match it with the
first observation with that ID?

Thanks!

Miriam
Miriam, look up "MATCH FILES (command)" under Help - Topics - Index, then click on the entry for the "Table subcommand".  You could also look for the match merging tutorial (under "intermediate data management") on the UCLA's  SPSS data management page (http://www.ats.ucla.edu/stat/SPSS/topics/data_management.htm).  

--
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/).