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
*(Q) I have a dataset that has missing values (sysmis) strewn throughout
	I want to create a table with the variable names containing missing data (VNAME), 
	the organization's id (OID), the medical record # (MEDRECNM), 
	and the reviewer's initials (REVIEWER).

* (A) Posted to SPSSX-L by  rlevesque@videotron.ca  on 2001/08/23
	The solution assumes that blank string variables are missing.


* In order to make the solution completely general. Two macros are used to do the job.

* Comments on first macro:
	Some commands do not accept references such as var1 TO xyz5
	This macro produces a list of all variables between 2 given variables
	If the 2 variables are not supplied, all variables are included
	The macro is useful when there are hundreds of variables
	Because of a 'feature' of the macro parser, it is sometimes necessary to enclose 
	the variable names in quotes. This is done in the macro qlist1 (see below).

*///////////////////////////////////////.
DEFINE !DefList (var1=!DEFAULT(ALL) !TOKENS(1)  
		/var2=!TOKENS(1) 
		/fname=!CMDEND)

GET FILE=!fname.
N OF CASES 1.

!IF (!var1 !NE ALL) !THEN
ADD FILES FILE=* /KEEP=!var1 TO !var2.
!IFEND

FLIP.

COMPUTE dummy=1.
MATCH FILES FILE=* /BY=dummy /FIRST=first /LAST=last.
DO IF first.
+	WRITE OUTFILE='c:\\temp\\list1.sps' / 'DEFINE !list1()' case_lbl.
+	WRITE OUTFILE='c:\\temp\\qlist1.sps' / 'DEFINE !qlist1()"' case_lbl'"'.
ELSE if not last.
+	WRITE OUTFILE='c:\\temp\\list1.sps' / " "case_lbl.
+	WRITE OUTFILE='c:\\temp\\qlist1.sps' / " '"case_lbl"'".
ELSE.
+	WRITE OUTFILE='c:\\temp\\list1.sps' /" "case_lbl ' !ENDDEFINE'.
+	WRITE OUTFILE='c:\\temp\\qlist1.sps' /" '"case_lbl"'" ' !ENDDEFINE'.
END IF.
EXECUTE.

GET FILE=!fname.
INCLUDE FILE='c:\\temp\\list1.sps'.
* qlist1 = list1 with quoted variable names.
INCLUDE FILE='c:\\temp\\qlist1.sps'.
!ENDDEFINE.
*///////////////////////////////////////.


/* This is the second macro. It refers to the macro !list which was created by the macro above */.

*/////////////////////////////.
DEFINE !getmiss (fname=!CHAREND('/') /show=!CMDEND)

!LET !first=1
!DO !var !IN (!EVAL(!list1))
+	GET FILE=!fname.
+	STRING vname(A8).
*	One of the following 2 lines results in an error, this is normal, just ignore it.
+	SELECT IF SYSMIS(!var).
+	SELECT IF LEN(RTRIM(!var))=0.
+	COMPUTE vname = !QUOTE(!var).
+	SAVE OUTFILE="c:\\data\\tempmissing.sav" /KEEP=vname !show.
	!IF (!first=0) !THEN 
+		GET FILE="c:\\data\\missing.sav".
+		CACHE.
+		EXECUTE.
+		ADD FILES /FILE=* /FILE="c:\\data\\tempmissing.sav".
	!IFEND
+	SAVE OUTFILE="c:\\data\\missing.sav" /KEEP=vname !show.	
	!LET !first=0
!DOEND

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

*********************.
****** Example 1.
*********************.
* The next command gets the list of all variables.
!DEfList fname="c:\\Program Files\\SPSS\\World95.sav".

* The next command produce the required table using variables country populatn region to identily records.
!getmiss fname="c:\\Program Files\\SPSS\\World95.sav" /show=country populatn region.
* (there are 104 missing information in the data file).

*********************.
****** Example 2.
*********************.
* The next command gets the list of all variables.
!DEfList fname="c:\\Program Files\\SPSS\\Employee data.sav".

* The next command produce the required table using variables id and jobcat to identily records.
!getmiss fname="c:\\Program Files\\SPSS\\Employee data.sav" /show=id jobcat.
* (there are only one data missing in the Employee data file).