1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
* (Q) How can I create a data file only if the 2 files entered separately 
	are identical.
* (A) By Ray 2002/08/23 (email question).

*The person who asked the question then made the following change. 
* "In case its helpful to anybody on the website, I've added a short step 
  after the first END IF command (3 lines beginning with TEMPORARY).  
  Basically this reports on where any discrepancies between the two 
  databases are located so they can be corrected.  If everything is OK, 
  it provides an error message, which is odd but it works. 
  Tim Vaughn Salomons."

DATA LIST LIST /id q1a q2a q3a q4a q1b q2b q3b q4b.
BEGIN DATA
100 2 4 6 8 2 4 6 8
101 2 4 6 8 2 4 6 8
102 2 4 6 8 2 4 6 8
END DATA.
LIST.
* In this file a and b are equal.
SAVE OUTFILE='c:\\temp\\file1.sav'.


DATA LIST LIST /id q1a q2a q3a q4a q1b q2b q3b q4b.
BEGIN DATA
100 2 4 6 8 2 4 6 8
101 2 4 6 8 . 4 6 8
102 2 4 6 8 2 4 6 8
END DATA.
LIST.
* In this file a and b do not agree (one missing value).
SAVE OUTFILE='c:\\temp\\file2.sav'.


DATA LIST LIST /id q1a q2a q3a q4a q1b q2b q3b q4b.
BEGIN DATA
100 2 4 6 8 2 4 6 8
101 2 4 6 8 . . 6 8
102 2 4 6 8 2 4 6 8
END DATA.
LIST.
* In this file a and b agree (2 values are missing).
SAVE OUTFILE='c:\\temp\\file3.sav'.


DATA LIST LIST /id q1a q2a q3a q4a q1b q2b q3b q4b.
BEGIN DATA
100 2 4 6 8 2 8 8 8
101 2 4 6 8 2 4 6 8
102 2 4 6 8 2 4 6 8
END DATA.
LIST.
* In this file a and b are different.
SAVE OUTFILE='c:\\temp\\file4.sav'.


*///////////////.
DEFINE !test(!POS=!TOKENS(1))
GET FILE=!QUOTE(!CONCAT('c:\\temp\\',!1,'.sav')).
VECTOR a=q1a TO q4a /b=q1b TO q4b.
LOOP qnb=1 TO 4.
COMPUTE a=a(qnb).
COMPUTE b=b(qnb).
XSAVE OUTFILE='c:\\temp\\temp.sav' 
	/KEEP=id qnb a b.
END LOOP.
EXECUTE.

GET FILE='c:\\temp\\temp.sav' .
* nbdif will contain # of differences.
COMPUTE nbdif=0.
DO IF NMISS(a,b)=1.
+	COMPUTE nbdif=1.
ELSE IF a<>b.
+	COMPUTE nbdif=1.
END IF.

TEMPORARY.
SELECT IF ( nbdif=1 ).      
REPORT FORMAT=list/var= id qnb a b.

COMPUTE nobreak=1.
AGGREGATE OUTFILE=*
	/BREAK=nobreak
	/nbdif=SUM(nbdif).
DO IF nbdif=0.
STRING fname1 fname2 (A15).
COMPUTE fname1=CONCAT(!QUOTE(!1),'.sav"').
COMPUTE fname2=CONCAT(!QUOTE(!1),' ok.sav"').
WRITE OUTFILE='c:\\temp\\syntax.sps' 
	/'GET FILE="c:\\temp\\'fname1
	/'SAVE OUTFILE="c:\\temp\\'fname2.
ELSE.
WRITE OUTFILE='c:\\temp\\syntax.sps' 
	/'* nothing to do.'.
END IF.
EXECUTE.
INCLUDE 'c:\\temp\\syntax.sps'. 

EXECUTE.
!ENDDEFINE.
*///////////////.

SET MPRINT=yes.
!test file1.
!test file2.
!test file3.
!test file4.