Bizarre Variable Behavior in SPSS-Python

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

Bizarre Variable Behavior in SPSS-Python

Krinsky, Alan-2
Bizarre Variable Behavior in SPSS-Python

Thanks to some help, I have learned to incorporate Python syntax to loop through unknown numbers of variables. Yesterday I discovered something bizarre going on, and I cannot figure out if I have an SPSS problem, a Python problem, some other coding problem, or some other problem.

Please see the code here, and I will explain the odd results below:


        * Step 7A: Compare Dispense Dates with Episode Dates to find matches for period from Episode Date through 3 Days post-Episode Date.

        GET
          FILE='\\server01\Network Analyses\Measure\DATA_File_Step 6B_2009Q1to2009Q4.sav'.
        DATASET NAME DataSet7A WINDOW=ASIS.
        SORT CASES BY patientID(A) servicedate(A).

        RECODE priority (ELSE=0) INTO DispensingEventMatch.
        VARIABLE LABELS  DispensingEventMatch 'DispensingEventMatch'.


BEGIN PROGRAM.
import spss, spssaux

vardict = spssaux.VariableDict(pattern="^servicedate")

for v1 in vardict.range():

      spss.Submit("""


        IF (%(v1)s >= EpisodeDate AND %(v1)s <= EpisodePlus3Date) DispensingEventMatch = 1.
        EXECUTE.

""" % locals())
END PROGRAM.

What is happening is that the DispensingEventMatch variable is transforming to 1, for all cases, regardless of whether or not it is true. However, if I use the same code, but use a different variable (for example, EpisodePlus3Date instead of EpisodePlus3Date), I get a mix of 0s and 1s, as appropriate for the date ranges. I have tried renaming the EpisodePlus3Date variable, recalculating it, looking for null values, reversing the 1s and 0s, removing the "range" piece from the Python code, restarting my computer, and nothing has worked or provided an explanation of why I am getting these incorrect and odd results.

Any thoughts? Thank you, and be well!

Alan


Alan D. Krinsky  PhD, MPH
Senior Data Analyst
UMass Memorial Health Care
Worcester, MA 01605
Phone: 508-334-5854
Fax: 508-793-6086
E-mail: [hidden email]

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
Reply | Threaded
Open this post in threaded view
|

Re: Bizarre Variable Behavior in SPSS-Python

Jon K Peck
See below.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "Krinsky, Alan" <[hidden email]>
To:        [hidden email]
Date:        08/02/2011 01:25 PM
Subject:        [SPSSX-L] Bizarre Variable Behavior in SPSS-Python
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Thanks to some help, I have learned to incorporate Python syntax to loop through unknown numbers of variables. Yesterday I discovered something bizarre going on, and I cannot figure out if I have an SPSS problem, a Python problem, some other coding problem, or some other problem.

Please see the code here, and I will explain the odd results below:

        * Step 7A: Compare Dispense Dates with Episode Dates to find matches for period from Episode Date through 3 Days post-Episode Date.

        GET
         FILE='\\server01\Network Analyses\Measure\DATA_File_Step 6B_2009Q1to2009Q4.sav'.
       DATASET NAME DataSet7A WINDOW=ASIS.

       SORT CASES BY patientID(A) servicedate(A).

        RECODE priority (ELSE=0) INTO DispensingEventMatch.
       VARIABLE LABELS  DispensingEventMatch 'DispensingEventMatch'.

BEGIN PROGRAM.
import spss, spssaux

vardict = spssaux.VariableDict(pattern="^servicedate")

for v1 in vardict.range():

      spss.Submit("""

        IF (%(v1)s >= EpisodeDate AND %(v1)s <= EpisodePlus3Date) DispensingEventMatch = 1.
       EXECUTE.

""" % locals())
END PROGRAM.

>>>Remove the EXECUTE command.  It forces a data pass for each variable rather than doing one data pass for all the variables in range.

The bug, though, is probably this: your code tests every variable in range, so if any of them meets the condition, DispensingEventMatch is set to 1.  Is that really the condition you want to test?

HTH,

Jon Peck

What is happening is that the DispensingEventMatch variable is transforming to 1, for all cases, regardless of whether or not it is true. However, if I use the same code, but use a different variable (for example, EpisodePlus3Date instead of EpisodePlus3Date), I get a mix of 0s and 1s, as appropriate for the date ranges. I have tried renaming the EpisodePlus3Date variable, recalculating it, looking for null values, reversing the 1s and 0s, removing the "range" piece from the Python code, restarting my computer, and nothing has worked or provided an explanation of why I am getting these incorrect and odd results.

Any thoughts? Thank you, and be well!

Alan

Alan D. Krinsky  PhD, MPH
Senior Data Analyst

UMass Memorial Health Care

Worcester, MA 01605

Phone: 508-334-5854

Fax: 508-793-6086

E-mail: [hidden email]

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.