|
Dear List,
I have 2 datafiles FileA and FileB with same variables, I want to Create a third datafile FileC containing only records from both FileA and FileB Where the values of the variables x1 , x2 and x3 (ie same matching records on x1,x2 and x3) in both datafiles are equal . Can somebody point me the right direction. Thanks Ucal ____________________________________________________________________________________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list&sid=396546091 |
|
One possibility:
Rename the variables in one of the files to, say, Z1, Z2 and Z3. Match the files (with all cases included). Then select the cases where X1=Z1 AND X2=Z2 AND X3=Z3. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ucal Gyam Sent: 11 July 2007 14:59 To: [hidden email] Subject: Combining Two Datafiles Dear List, I have 2 datafiles FileA and FileB with same variables, I want to Create a third datafile FileC containing only records from both FileA and FileB Where the values of the variables x1 , x2 and x3 (ie same matching records on x1,x2 and x3) in both datafiles are equal . Can somebody point me the right direction. Thanks Ucal ____________________________________________________________________________ ________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list&sid=396546091 |
|
In reply to this post by Ucal Gyam
Hector, thanks for your response.
Should I first rename the variables in the second file , add the files then match the files ? , more details on how to do this will be much appreciated. Thanks. ----- Original Message ---- From: Hector Maletta <[hidden email]> To: [hidden email] Sent: Wednesday, July 11, 2007 2:14:07 PM Subject: Re: Combining Two Datafiles One possibility: Rename the variables in one of the files to, say, Z1, Z2 and Z3. Match the files (with all cases included). Then select the cases where X1=Z1 AND X2=Z2 AND X3=Z3. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ucal Gyam Sent: 11 July 2007 14:59 To: [hidden email] Subject: Combining Two Datafiles Dear List, I have 2 datafiles FileA and FileB with same variables, I want to Create a third datafile FileC containing only records from both FileA and FileB Where the values of the variables x1 , x2 and x3 (ie same matching records on x1,x2 and x3) in both datafiles are equal . Can somebody point me the right direction. Thanks Ucal ____________________________________________________________________________ ________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list&sid=396546091 ____________________________________________________________________________________ Finding fabulous fares is fun. Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains. http://farechase.yahoo.com/promo-generic-14795097 |
|
It does not matter which file's variables you rename insofar they have
different names. Example of syntax: Both files must be sorted by the matching variables (e.g. the ID variable in the following example). GET FILE 'FILE1.SAV'. RENAME VARIABLES (X1 X2 X3 = Z1 Z2 Z3). SORT CASES BY ID. SAVE OUTFILE 'FILE1.SAV'. GET FILE 'FILE2.SAV'. SORT CASES BY ID. MATCH FILES /FILE */FILE 'FILE1.SAV'/BY ID. SELECT IF (X1=Z1 AND X2=Z2 AND X3=Z3). SAVE OUTFILE 'SELECTEDCASES.SAV'. Hector _____ From: Ucal Gyam [mailto:[hidden email]] Sent: 11 July 2007 16:05 To: Hector Maletta; [hidden email] Subject: Re: Combining Two Datafiles Hector, thanks for your response. Should I first rename the variables in the second file , add the files then match the files ? , more details on how to do this will be much appreciated. Thanks. ----- Original Message ---- From: Hector Maletta <[hidden email]> To: [hidden email] Sent: Wednesday, July 11, 2007 2:14:07 PM Subject: Re: Combining Two Datafiles One possibility: Rename the variables in one of the files to, say, Z1, Z2 and Z3. Match the files (with all cases included). Then select the cases where X1=Z1 AND X2=Z2 AND X3=Z3. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ucal Gyam Sent: 11 July 2007 14:59 To: [hidden email] Subject: Combining Two Datafiles Dear List, I have 2 datafiles FileA and FileB with same variables, I want to Create a third datafile FileC containing only records from both FileA and FileB Where the values of the variables x1 , x2 and x3 (ie same matching records on x1,x2 and x3) in both datafiles are equal . Can somebody point me the right direction. Thanks Ucal ____________________________________________________________________________ ________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list <http://answers.yahoo.com/dir/?link=list&sid=396546091> &sid=396546091 _____ Don't get soaked. Take a quick peak at the forecast with theYahoo! Search weather shortcut. |
|
In reply to this post by Ucal Gyam
At 01:59 PM 7/11/2007, Ucal Gyam wrote:
>I have 2 datafiles FileA and FileB with same variables, I want to >Create a third datafile FileC containing only records from both FileA >and FileB Where the values of the variables x1 , x2 and x3 (ie same >matching records on x1,x2 and x3) in both datafiles are equal . If I read you correctly: if records match (on those three variables) in both files, you want to keep both records in your output file, not merge them into one. (The latter won't give the desired results anyway, if there both files have the same variables.) The following is not tested. It assumes that FileA, FileB, FileC are valid file references, perhaps file handles. It uses datasets (SPSS 14 and beyond). If you have an earlier SPSS, you can make srtFileB a scratch .SAV file, changing the dataset-handling logic to file-handling logic. This logic leaves variables FrmFileA, FrmFileB, InFileA and InFileB in the output file. I think you should keep the first two of these. If you don't want the others, add /DROP InFileA InFileB to your SAVE statement. GET FILE=FileB. SORT CASES BY x1 x2 x3. DATASET NAME srtFileB. GET FILE=FileA. SORT CASES BY x1 x2 x3. ADD FILES /FILE=* /IN=FrmFileA /FILE=srtFileB /IN=FrmFileB /BY x1 x2 x3. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK = x1 x2 x3 /InFileA 'x1-x2-x3 key found in FileA' = MAX(FrmFileA) /InFileB 'x1-x2-x3 key found in FileB' = MAX(FrmFileB). SELECT IF FrmFileA EQ 1 AND FrmFileB EQ 1. SAVE OUTFILE=FileC. |
|
In reply to this post by Ucal Gyam
Thanks for your response Richard .
You are right , if records match (on those three variables) in both files, I want to keep both (all) records in my output file, not merge them into one. Which part of syntax wont give me desired results if there both files have the same variables? ----- Original Message ---- From: Richard Ristow <[hidden email]> To: [hidden email] Sent: Wednesday, July 11, 2007 11:55:02 PM Subject: Re: Combining Two Datafiles At 01:59 PM 7/11/2007, Ucal Gyam wrote: >I have 2 datafiles FileA and FileB with same variables, I want to >Create a third datafile FileC containing only records from both FileA >and FileB Where the values of the variables x1 , x2 and x3 (ie same >matching records on x1,x2 and x3) in both datafiles are equal . If I read you correctly: if records match (on those three variables) in both files, you want to keep both records in your output file, not merge them into one. (The latter won't give the desired results anyway, if there both files have the same variables.) The following is not tested. It assumes that FileA, FileB, FileC are valid file references, perhaps file handles. It uses datasets (SPSS 14 and beyond). If you have an earlier SPSS, you can make srtFileB a scratch .SAV file, changing the dataset-handling logic to file-handling logic. This logic leaves variables FrmFileA, FrmFileB, InFileA and InFileB in the output file. I think you should keep the first two of these. If you don't want the others, add /DROP InFileA InFileB to your SAVE statement. GET FILE=FileB. SORT CASES BY x1 x2 x3. DATASET NAME srtFileB. GET FILE=FileA. SORT CASES BY x1 x2 x3. ADD FILES /FILE=* /IN=FrmFileA /FILE=srtFileB /IN=FrmFileB /BY x1 x2 x3. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK = x1 x2 x3 /InFileA 'x1-x2-x3 key found in FileA' = MAX(FrmFileA) /InFileB 'x1-x2-x3 key found in FileB' = MAX(FrmFileB). SELECT IF FrmFileA EQ 1 AND FrmFileB EQ 1. SAVE OUTFILE=FileC. ____________________________________________________________________________________ Pinpoint customers who are looking for what you sell. http://searchmarketing.yahoo.com/ |
|
In reply to this post by Ucal Gyam
Thanks Richard and Hector , I was able to adapt your syntax to solve my proble.
----- Original Message ---- From: Richard Ristow <[hidden email]> To: [hidden email] Sent: Wednesday, July 11, 2007 11:55:02 PM Subject: Re: Combining Two Datafiles At 01:59 PM 7/11/2007, Ucal Gyam wrote: >I have 2 datafiles FileA and FileB with same variables, I want to >Create a third datafile FileC containing only records from both FileA >and FileB Where the values of the variables x1 , x2 and x3 (ie same >matching records on x1,x2 and x3) in both datafiles are equal . If I read you correctly: if records match (on those three variables) in both files, you want to keep both records in your output file, not merge them into one. (The latter won't give the desired results anyway, if there both files have the same variables.) The following is not tested. It assumes that FileA, FileB, FileC are valid file references, perhaps file handles. It uses datasets (SPSS 14 and beyond). If you have an earlier SPSS, you can make srtFileB a scratch .SAV file, changing the dataset-handling logic to file-handling logic. This logic leaves variables FrmFileA, FrmFileB, InFileA and InFileB in the output file. I think you should keep the first two of these. If you don't want the others, add /DROP InFileA InFileB to your SAVE statement. GET FILE=FileB. SORT CASES BY x1 x2 x3. DATASET NAME srtFileB. GET FILE=FileA. SORT CASES BY x1 x2 x3. ADD FILES /FILE=* /IN=FrmFileA /FILE=srtFileB /IN=FrmFileB /BY x1 x2 x3. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK = x1 x2 x3 /InFileA 'x1-x2-x3 key found in FileA' = MAX(FrmFileA) /InFileB 'x1-x2-x3 key found in FileB' = MAX(FrmFileB). SELECT IF FrmFileA EQ 1 AND FrmFileB EQ 1. SAVE OUTFILE=FileC. ____________________________________________________________________________________ Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php |
| Free forum by Nabble | Edit this page |
