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
'The following script will determine quickly the # of cases
'And tell you if your base is weighted or not. If it is, it
'will prompt you whether you want or not to calculate the
'weighted number of cases. If you choose OK, it will:

'Turn the weight off
'Get the sum of the weight var (descriptives), which is equal
'To the weighted number of cases
'Turn the weight on again.

'You can create a custom menu item that points to the script
'file, or choose run script from utilities menu.

'This solution is very handy for unweighted bases.

'RGDS

'Rafael Osorio (usenet 11 May 2000)re:Finding number of cases

Option Explicit

Dim DtDoc As ISpssDataDoc
Dim OutDoc As ISpssOutputDoc
Dim WeightName As String
Dim Cmd As String

Sub Main
	Set DtDoc = objSpssApp.Documents.GetDataDoc(0)
	WeightName = DtDoc.GetWeightingVariable(False)
	If WeightName = "" Then
		MsgBox "Weight is off: number of cases = "&DtDoc.GetNumberOfCases		
	Else
		If MsgBox("Weight (" &WeightName &") is on:UNWEIGHTED number of cases = " _
		   &DtDoc.GetNumberOfCases &". Press OK to calculate the weighted number.", 1) = 2 _
		   Then Exit Sub
		
		Set OutDoc = objSpssApp.NewOutputDoc
		OutDoc.Visible = True
		Cmd = "WEIGHT OFF." & vbCr
		Cmd = Cmd &"FILTER OFF." & vbCr
		Cmd = Cmd &"DESCRIPTIVES " & WeightName & "/STATISTICS=SUM." &vbCr
		Cmd = Cmd &"WEIGHT BY " & WeightName &"."&vbCr
		objSpssApp.ExecuteCommands Cmd, False
	End If
End Sub