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
109
110
111
112
113
114
115
116
117
118
119
120
 

'SPSS AnswerNet: Result 

'Solution ID:  100006745 
'Title: Breaking Output into smaller files 

'Q. 
'I have SPSS For Windows 8.0, And I am running several syntax files (perhaps 
'using Production Mode). The Output from this job All goes into a Single 
'file, which becomes enormous. Is there Any way I can break the Output 
'up into smaller files? 

'A. 
'Yes, you can add a script Command To Each Command syntax file To 
'tell SPSS To save the Output, And supply the Name (And optionally the 
'path) For Each file you want saved. Simply save the indicated portion of 
'this note As a script (.SBS) file, And trigger the script As shown In the 
'Command syntax example below. If the script And syntax which triggers it 
'are In the same directory, you may Not need To specify the full path, 
'although the example shows this. You may specify a full path For the 
'file To be saved; If you Do Not, it will be saved In the SPSS 
'directory. 

'One possibility If you are using Production Mode Is To add a script 
'Command at the End of Each syntax file, specifying For the Output file 
'the same Name As the syntax, but With the .SPO extension. 

'You may want To Print the windows, As well As save them. You can Do 
'this by finding the following pair of lines In the script below: 

'Remove the ' from the following line to print all output: 
'objOutputDoc.PrintDoc 

'Follow the instructions To remove the Single-quote character at the 
'beginning of the Second Line, And your Output will be printed As well 
'As saved. 

'***** Save this portion As a syntax file "SaveClose.SPS" *****. 

'*Example of how To use a script To save Output With a specified Name. 
'*Add the SCRIPT Command at the End of Each syntax file. 
'*Can be used With a production job To save Output To multiple files. 

'*Requires SPSS 8.0. 

'*Example syntax... please use your own syntax. 

'Get 
'FILE='C:\\Program Files\\SPSS\\Cars.sav'. 
'DESCRIPTIVES 
'VARIABLES=mpg engine horse weight accel Year origin cylinder filter_$ 
'/STATISTICS=MEAN STDDEV MIN MAX . 
'EXECUTE . 

'*This syntax executes the script And passes a filename As an argument. 
'*The script opens a New Output window, And saves the existing Output. 

'SCRIPT file="c:\\program files\\spss\\scripts\\SaveClose.sbs" '/("SaveClose.spo") . 

'***** End of syntax example *****. 

'Save this portion as the Script file "SaveClose.SBS" 

'Begin Description 
'This script demonstrates how arguments can be passed into a script when 
'the script is run using the SCRIPT command in a syntax file. 
'To run this script, open 'SaveClose.sps' syntax file and run the 
'syntax. The script saves the designated Viewer file as the name 
'specified by the argument in the SPSS directory. 
'Requirements: The script must be run from the 'SaveClose.sps' syntax 
'file. 

Option Explicit 

Sub Main 
'limit the number of open windows 
'Const MAX_WINDOWS As Integer = 10 
'Used to save the currently open Viewer doc 
'and create a new Viewer doc 
Dim objOutputDoc As ISpssOutputDoc 
Dim strParam As String 

Dim i As Integer 
Dim objDocuments As ISpssDocuments 

Set objDocuments = objSpssApp.Documents 

strParam = objSpssApp.ScriptParameter(0) 
If objDocuments.OutputDocCount > 0 And strParam <> "" Then 
Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc 
'Remove the ' from the following line to print all output: 
'objOutputDoc.PrintDoc 
'check to see if the user specified a path 
If InStr(strParam, "\\") > 0 Then 
objOutputDoc.SaveAs strParam 
Else 'if no path specified, use the current directory 
objOutputDoc.SaveAs objSpssApp.GetSPSSPath & strParam 
End If 
End If 

'open a new window and make it visible 
'objSpssApp.NewOutputDoc.Visible = True 
'or just open a new window (e.g. for Production Mode) 
objSpssApp.NewOutputDoc 
'and close the old ones ... 
'but only if it's not designated, 
'and there are fewer than MAX_WINDOWS 
'If objDocuments.OutputDocCount < MAX_WINDOWS Then Exit Sub 
For i = objDocuments.OutputDocCount - 1 To 0 Step -1 
Set objOutputDoc = objDocuments.GetOutputDoc(i) 
If Not objOutputDoc.Designated Then 
objOutputDoc.Close 
End If 
Next 
End Sub 

'End of script