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
*(Q) say I have a field, x, with what is supposed to be SSNs
 (social security #s).  What I want to do is see how many observations
 have incorrect data.


*(A) Posted to newsgroup by Raynald Levesque on 2002/08/01.

* Sample data.
DATA LIST FIXED /ssn 1-11 (A).
BEGIN DATA
123-45-6789
1234-5-6789
12e-45-6789
123&45-2222
END DATA.
LIST.

* Test the 2 "-".
COMPUTE test1=SUBSTR(ssn,4,1)="-" & SUBSTR(ssn,7,1)="-".

* test that the other entries are digits.
COMPUTE test2=~MISSING(NUMBER(CONCAT(SUBSTR(ssn,1,3),SUBSTR(ssn,5,2),SUBSTR(ssn,8)),F9.0)).
COUNT error=test1 test2 (0).
EXECUTE.

* The variable error gives the number of error detected.