|
Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621
From:
ChetMeinzer <[hidden email]>
To:
[hidden email],
Date:
04/04/2013 04:17 PM
Subject:
[SPSSX-L] Dynamic
vector based on numeric variable
Sent by:
"SPSSX(r)
Discussion" <[hidden email]>
Is it possible to use a dynamic variable for the parameter
that 'vector'
takes?
for example:
compute CountMonthsSinceX=datediff($time,date.dmy(1,7,2011),"months").
vector dateEp(CountMonths,f11).
>>>No. The computed variable is a casewise
variable while a scalar is required here. But you can do this with
a touch of Python programmability using the spssaux3.py module available
from the SPSS Community site.
begin program.
import spss, spssaux3
diff = spssaux3.getComputations("""compute
CountMonthsSinceX=
datediff($time,date.dmy(1,7,2011),"months").""",
values = [[1]])
spss.Submit("""vector dateEp(%s,f11)."""
% diff[0])
end program.
The getComputations function creates a dataset with
the case values as specified in the values argument - here just one case
with one variable with a value of 1. Then it runs the compute command
and returns a list of values - here a list of length 1.
The spss.Submit call substitutes that value into the
vector syntax and executes it.
Note: since getComputations creates a new dataset,
your active dataset when this program is run should have a dataset name
or it will be closed by the creation of a new dataset.
Regards,
Jon Peck
|