*Sorry for the double, the web interface did something strange*
Dear all, I need to merge two datasets to add a new variable. The structure of the two datasets is the following: COUNTRY YEAR Value AAA 1800 666 AAA 1900 100 BBB 1800 777 BBB 1900 88 ... .... ... The "Key Variables" are COUNTRY and YEAR. The expected results is to have a dataset with COUNTRY, YEAR, Value1 and Value2. THE QUESTION: Now, the first DataSet1 has 50 countries, and DataSet2, has more than 100 countries. When I merge the two files together, I just need to keep the 50 countries of DataSet1, without integrating all the others. When I use the standard command*, I find myself with a dataset of 100 countries, because all the cases from DataSet2 are integrated as well. How can I merge the two datasets using only the cases of DataSet1? In other words, how can I add variables without adding new cases to my "Key Variables"? best, luther. * The command I use is: DATASET ACTIVATE DataSet1. SORT CASES BY COUNTRY YEAR. DATASET ACTIVATE DataSet2. SORT CASES BY COUNTRY YEAR. DATASET ACTIVATE DataSet1. MATCH FILES /TABLE=* /FILE='DataSet2' /BY COUNTRY YEAR. EXECUTE. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
There are several ways. One is simply to create teh big file and then delete
the unwanted cases. Something like this untested modification to your posted syntax. DATASET ACTIVATE DataSet1. SORT CASES BY COUNTRY YEAR. DATASET ACTIVATE DataSet2. SORT CASES BY COUNTRY YEAR. DATASET ACTIVATE DataSet1. MATCH FILES /FILE =* /IN= InOldSet /FILE=DataSet2 /InNewSet /BY COUNTRY YEAR. dataset name combined. Crosstabs Tables = InOldSet by InNewSet. Do If InOldSet and NOT InNewSet. do repeat NV = NewVar1 to NewVar8. compute NV = -1. end repeat. Missing values NewVar1 to NewVar8 (-1). Value labels NewVar to NewVar8 -1 'missing in new data because something or other'. Select if InOldSet. Execute. This will work if you do not really need TABLE=, i.e., you do not have repeats on the key variables in the new file. ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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
Art Kendall
Social Research Consultants |
Dear Art,
Thank you for your answer! It works. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
In reply to this post by luther
The files are backwards in the MATCH FILES command. You want the 50-county file to be the active file and the other one to be the TABLE file. From the Syntax Reference... TABLE specifies a table lookup (or keyed table) file. A lookup file contributes variables but not cases to the new active dataset. Variables from the table file are added to all cases from other files that have matching values for the key variables. FILE specifies the files that supply the cases. On Mon, Feb 11, 2019 at 5:18 AM luther <[hidden email]> wrote: *Sorry for the double, the web interface did something strange* |
That is a good catch.
Also, it would be important to first verify that any specific combination of keys occurred only once in each file. My suggested syntax also corrected for keeping sysmis values in the resulting data set when there was a known reason for the missingness. ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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
Art Kendall
Social Research Consultants |
Free forum by Nabble | Edit this page |