* =================================================================== File: double_entry_check.sps Author: Bruce Weaver, bweaver@lakeheadu.ca Date: 29-Oct-2004 Notes: Check double-entered data for consistency . * =================================================================== . * First, create a couple of sample files . DATA LIST LIST /entry ID a b (4f3.0) c (a3) . BEGIN DATA. 2 101 2 4 abc 2 102 1 3 def 2 104 1 2 fhi 2 105 2 4 jkl 2 106 4 3 mno END DATA. save outfile = 'c:\temp\file2.sav'. DATA LIST LIST /entry ID a b (4f3.0) c (a3) . BEGIN DATA. 1 101 2 4 abc 1 102 1 3 xyz 1 103 3 3 hey 1 104 1 3 fhi 1 105 2 4 man END DATA. * Now add data from FILE2.SAV . add files file = * /file = 'c:\temp\file2.sav'. exe. sort cases by id entry. numeric flag1 to flag4 flag (f1.0). compute #ok = (entry=2) and lag(entry)=1 and id=lag(id). do if #ok. do repeat v1 = a to c / v2 = flag1 to flag3. - compute v2 = (v1 NE lag(v1)). end repeat. end if. * FLAG1=1 indicates mismatch for variable A. * FLAG2=1 indicates mismatch for variable B. * FLAG3=1 indicates mismatch for variable C. * Now get number of entries for each ID number--should be two. match files file = * /by id /first=first /last = last. compute recnum=first. if not first recnum = lag(recnum)+1. sort cases by id recnum(d). do if last. - compute numrecs = recnum. else. - compute numrecs = lag(numrecs). end if. if (numrecs ne 2) flag4 = 1. /* <--- set Flag4 here . compute #sum = sum(flag1 to flag4). if (#sum > 0) flag = 1. /* <--- general flag. sort cases by id entry. list entry to flag. * FLAG1=1 indicates mismatch for variable A. * FLAG2=1 indicates mismatch for variable B. * FLAG3=1 indicates mismatch for variable C. * FLAG4=1 indicates that number of records is not 2. * FLAG =1 indicates a general problem. * =================================================================== .