do repeat l1=op1 to op67
/l2=1 to 67.
compute l1=0.
do if(operator=l2).
compute l1=charge.
end if.
end repeat.
aggregate outfile=.../break=diary
/op1 to op67=sum(op1 to op67).
/*in fact I have a separate line for each aggregate variable so I can edit
the syntax easily.
>The script facility doesn't look like it applies to syntax.
Maybe this script is useful:
Option Explicit
Sub Main
Dim objDataDoc As ISpssDataDoc
Dim operators As Variant
Dim NOC As Integer
Dim i As Integer
Dim max As Integer
Dim operator As Integer
Set objDataDoc = objSpssApp.Documents.GetDataDoc (0)
NOC = objDataDoc.GetNumberOfCases
sto = objDataDoc.GetTextData ("operator", "operator", 1, NOC)
max = 0
For i = 0 To NOC - 1
operator = Val (operators (0, i))
If operator > max Then max = operator
Next i
Open "count_op.inc" For Output As #1
Print #1, "DEFINE !COUNTOP () " & Format (max) & " !ENDDEFINE ."
Print #1, "DEFINE !VAROP () op" & Format (max) & " !ENDDEFINE ."
Close #1
End Sub
The script looks for the highest value of the variable "operator" in
the current data. It creates an include file "count_up.inc", which
defines two macros: the count itself (!COUNTOP) and the last variable
name (!VAROP).
Call it with 'script' from your syntax, then 'include' the created
syntax file, then use the macros in your existing program.
This is in SPSS for Windows 8.0; IIRC in 9.0 data access from scripts
has changed.
HTH
--
Kai Borgolte, Bonn
>I want to generate a variable for each respondent in a regular survey for
>each transport operator.
>I'd like to be able to generate this without having to edit the syntax for
>the number of operators, which changes with every survey.
>I look at the Macro facility - but it doesn't seem to have any way of
>putting in the value of a variable into its string substitution. I can
- If you just want to use a set of Variables, one way is to use a
macro to define something like Var_set -- and then change that
definition for each run.
But incorporating a value into a name is not impossible. Here is one
example (from vers 6, no periods on the lines).
/* example of ANOVA where "/STATISTICS" is passed as an option, and
/* the variable names (suffix of 1,2,...) are created by
concatenation
/* in the Macro.
/* macro M_ANOV anova with covariates, optional MCA will be statistic
/* invoked M_ANO IND=6 COV=1 GPS= MEDS(1,3)% STAT= /STATISTCS= MCA
/* to indicate week 6 for indep var, and week 1 for covariate.
DEFINE M_ANCOV (IND= !TOKENS(1)/
COV= !TOKENS(1)/
GPS= !CHAREND('%')/
STAT= !CMDEND)
ANOVA !CONCAT(GAS,!IND) BY !GPS WITH !CONCAT(GAS,!COV)
/!CONCAT(GASSELF,!IND) BY !GPS WITH !CONCAT(GASSELF,!COV)
/!CONCAT(HAM_L,!IND) BY !GPS WITH !CONCAT(HAM_L,!COV)
/!CONCAT(HAM_S,!IND) BY !GPS WITH !CONCAT(HAM_S,!COV)
/!CONCAT(BECK,!IND) BY !GPS WITH !CONCAT(BECK,!COV)
!STAT
!ENDDEFINE
GET FILE= 'PER7.DBT'
TITLE examine time-to-dropout vs. med groups
SUBTITLE does initial difference predict dropout time?
M_ANOV IND=1 GPS= WKS_T(1,5) MEDS(1,3) STAT_22(1,2) % STAT=
/STATISTICS= MCA
SUBTITLE how different are the drop-evaluations? use IND=7
M_ANOV IND=7 GPS= WKS_T(1,5) ...
====
by the way, this related syntax, below, looks unwieldy, and could
probably be replaced by a use of a Vector -- all that is needed
instead of any loop is one more statement (after VECTOR)
COMPUTE op(operator)=charge .
>
>do repeat l1=op1 to op67
>/l2=1 to 67.
>compute l1=0.
>do if(operator=l2).
>compute l1=charge.
>end if.
>end repeat.
>aggregate outfile=.../break=diary
> /op1 to op67=sum(op1 to op67).
>/*in fact I have a separate line for each aggregate variable so I can edit
>the syntax easily.
>
--
Rich Ulrich, wpi...@pitt.edu
>I want to generate a variable for each respondent in a regular survey for
>each transport operator.
>I'd like to be able to generate this without having to edit the syntax for
>the number of operators, which changes with every survey.
>I look at the Macro facility - but it doesn't seem to have any way of
>putting in the value of a variable into its string substitution. I can
>aggregate a one-record file that has the number of operators in fairly
>easily.
>The other route I have used is to write out syntax with write statements and
>then to include them. However this is messy and usually requires
>hand-editing, or separate steps.
>The script facility doesn't look like it applies to syntax.
>Any SPSS wizards out there with a solution?
>For those of you who are concrete thinkers here is crucial part of the
>existing code.
>I want op67 to be op62 if there are 62 operators here (and 67 to become 62)
>and in several other places without my having to go through changing it
>every survey. I don't want to have to call the macro with the argument 62, I
>want to call it with an argument which substitutes the value of 62 from a
>variable. I want it to be automatic so that when I do the next survey I
>don't have to waste time changing 67's to 62 throughout the syntax. I want
>it to find out the number of operators and substitute it where necessary.
>
>do repeat l1=op1 to op67
>/l2=1 to 67.
>compute l1=0.
>do if(operator=l2).
>compute l1=charge.
>end if.
>end repeat.
>aggregate outfile=.../break=diary
> /op1 to op67=sum(op1 to op67).
>/*in fact I have a separate line for each aggregate variable so I can edit
>the syntax easily.
>
>
I refer to the script suggested by Kai Borgolte.
He has a very elegant solution. However that the following comments
should help you to implement his solution.
1. There is a typo in the script suggested: the expression "sto"
should be replaced by "operators" (see the line after
NOC = objDataDoc.GetNumberOfCases)
2.In SPSS 8, when the SCRIPT command is used in a syntax to call a
script, the script is executed AFTER ALL the selected commands within
the syntax have been run. I know that this is not logical... This is
not what one would "expect" from SPSS.
Thus if you run the full syntax in one shot, the file count_op.inc
which is supposed to be included early in the syntax, will NOTexit
yet.. This creates an error the first time the syntax is run.
If you have this problem, see the instructions below.
HTH
Raynald Levesque rlev...@videotron.ca
**************************
Here is the syntax file:
**************************
** INSTRUCTIONS if syntax does not work as is, try next 3 steps:
* Step 1: you must first select the syntax lines from here up to the
******.
* Step 2: run these lines
* Step 3: run the rest of the syntax.
set mexpand=on.
GET FILE='C:\Program Files\SPSS\test\operator.sav'.
EXECUTE.
* call script to get the max value of operators and make the include
file.
SCRIPT "c:\temp\count_op.sbs".
*******.
INCLUDE "c:\temp\count_op.inc".
DEFINE !DOIT().
VECTOR !CONCAT('op(',!COUNTOP,').').
COMPUTE op(operator)=charge.
SORT CASES BY diary.
AGGREGATE
/OUTFILE=*
/BREAK=diary
/op1 TO !varop = SUM(op1 TO !varop).
!ENDDEFINE.
* call macro.
!DOIT.
Neila Nessa wrote in message ...
>Here is another (I believe more general and efficient) way of achieving
this
>.
>Note by preaggregating and reverse sorting we need to grab the only the
>first
>case in the Gettextdata call. By moving the final aggregation into the
>script
>I reduce the synchronization problems however notice FREQ still works with
>the original file (I have never found a way to send commands synchronously
>from script!!!;-(
>This could be modified to take a parameter string.
>Neila
>
>DATA LIST FREE / operator diary charge .
>begin data
>1 1 12 1 1 33 1 1 33 1 2 22 1 2 11
>2 1 30 2 1 21 2 2 34 2 3 12 2 3 20
>3 1 20 3 2 30 3 2 20 3 3 40 3 4 45
>4 1 11 4 2 34 4 3 23 4 4 23 4 4 12
>end data .
>
>* AGGREGATE and reverse the sort FIRST* .
>AGGREGATE OUTFILE * / BREAK operator diary / charge = Sum(charge) .
>* First of all sort descending *.
>SORT CASES BY operator (D).
>Script "C:\Temp\Spread.sbs" .
>FREQ Diary .
>
>'"C:\Temp\Spread.sbs" contains
>Option Explicit
>Sub Main
> Dim sto As Variant
> Dim Max As Long
> Dim strControl As String
> Dim strSPSSCommand As String
>
> sto = objSpssApp.Documents.GetDataDoc (0).GetTextData ("operator",
>"operator", 1, 1)
> Max = sto (0,0)
> strControl = "OP1 To OP" & Max
> strSPSSCommand = _
> "NUMERIC " & strControl & "." & vbCrLf & _
> "VECTOR OP = " & strControl & "." & vbCrLf & _
> "LOOP # = 1 TO " & Max & "." & vbCrLf & _
> "IF operator = # OP(#) = Charge ." & vbCrLf & _
> "END LOOP." & vbCrLf & _
> "AGGREGATE Outfile * / Break Diary / " & strControl & " = MAX(" &
>strControl & ")."
> objSpssApp.ExecuteCommands(strSPSSCommand,False)
>End Sub
>
>Raynald Levesque wrote in message <37b4c3a7....@news.videotron.ca>...
Raynald and Neila, thanks for your comments.
>>(I have never found a way to send commands synchronously
>>from script!!!;-(
I thought, writing an include file from the script (rather than use
ExecuteCommands) would be a solution, but I was wrong.
**** test.sps **** .
data list / v1 to v3 1 - 6 .
begin data
1 2 3
end data.
frequencies variables = v1 .
script 'e:\test.sbs' .
include 'e:\test.inc' .
erase file = 'e:\test.inc' .
frequencies variables = v3 .
' **** test.sbs **** .
Sub Main
Open "e:\test.inc" For Output As #1
Print #1, "frequencies variables = v2 ."
Close #1
MsgBox "test.sbs is running, test.inc has been written"
End Sub
This is weird. The program generates the first frequency table, then
displays the message box and stops. Last element in the output window
is an empty log object, the actually executed 'script'-command shows
up later. Test.inc is written, you can proof this in Windows Explorer.
After closing the message box the syntax continues, but with errors
(if there is no old e:\test.inc from a previous run). This is in the
log:
script 'e:\test.sbs' .
include 'e:\test.inc' .
>Error # 31 in column 9. Text: e:\test.inc
>File not found.
>This command not executed.
erase file = 'e:\test.inc' .
>Error # 2302 in column 14. Text: e:\test.inc
>The specified file does not exist and cannot be erased.
>This command not executed.
frequencies variables = v3 .
Next element is the table for v3. I am confused. How is this possible?
--
Kai Borgolte, Bonn
Therefore I think the only solid solution is to leave all control to
the scriptprocessor by imbedding all syntax in the script.
I hope someone from spss will comment on this, perhaps there is
another solution.
best regards
Rolf
On Mon, 16 Aug 1999 09:33:45 GMT, Kai.Bo...@home.ivm.de (Kai
Borgolte) wrote:
>"Neila Nessa" <neila...@email.msn.com> schrieb in
><u7wN5Qq5#GA.368@cpmsnbbsa02>:
>
>Raynald and Neila, thanks for your comments.
>
>>>(I have never found a way to send commands synchronously
>>>from script!!!;-(
>
--
email: rolf.k...@get2net.dk
webpage: http://hjem.get2net.dk/rolf.kjoeller