*(Q) I would like to merge to files based on a many to many two variables,
neither of which are unique.
* The first file has two variables:
--the first variable is unique,
--the second variable is shared by groups of the first variable, so
that none of the values for this variable are necessarily unique.
* The second file also has the second variable mentioned above for the
first file.
* Again, none of these variables are necessarily unique.
* My goal is to get a merged file that multiples all of the first
variables in the first file times each case in the second file, where
the second variable in the first file = the variable in the second
file.
* Example:
*First File
V1 V2
1 A
2 A
3 A
4 B
5 B.
*Second File
A
A
B.
* End result should be:
1 A
2 A
3 A
1 A
2 A
3 A
4 B
5 B.
*(A) Posted to SPSS newsgroup by Raynald Levesque on 2002/03/29.
DATA LIST LIST /v1(F8.0) v2(A1).
BEGIN DATA
1 A
2 A
3 A
4 B
5 B
END DATA.
SORT CASES BY v2.
SAVE OUTFILE='c:\\temp\\datafile1.sav'.
NEW FILE.
DATA LIST LIST /v2(A1).
BEGIN DATA
A
A
B
END DATA.
SAVE OUTFILE='c:\\temp\\datafile2.sav'.
***** Start job.
GET FILE='c:\\temp\\datafile2.sav'.
COMPUTE nobreak=1.
AGGREGATE
/OUTFILE=*
/BREAK=v2
/nb = N(nobreak).
MATCH FILES TABLE=*
/FILE='c:\\temp\\datafile1.sav'
/BY v2.
WEIGHT CASES BY nb.
* For all practical purposes, the above gives you what you need.
* But in case you need the actual cases (not just a weigthed
file giving you the same number of cases), see
"Expand crosstab data into original data file.SPS" in
http://pages.infinit.net/rlevesqu/SampleSyntax.htm#ReadWriteOrCreateData