Dynamic vector based on numeric variable

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic vector based on numeric variable

ChetMeinzer
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).

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic vector based on numeric variable

Jon K Peck


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

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic vector based on numeric variable

ChetMeinzer
Thank you Jon!
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Dynamic vector based on numeric variable

David Fine


I am out of the office until 4/19 but will reply to your email within 24 hours. If you need immediate assistance please call my office (206-447-9538) and ask to speak with Roberta Domres or any staff person.

 

David Fine, PhD

Vice President

Cardea — Seattle, WA

p: (206) 447-9538 f: (206) 447-9539

[hidden email]

www.cardeaservices.org