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
RECODE priority (ELSE=0) INTO DispensingEventMatch.
BEGIN PROGRAM.
vardict = spssaux.VariableDict(pattern="^servicedate") for v1 in vardict.range(): spss.Submit(""" IF (%(v1)s >= EpisodeDate AND %(v1)s <= EpisodePlus3Date) DispensingEventMatch = 1.
""" % locals())
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
|
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
RECODE
priority (ELSE=0) INTO DispensingEventMatch.
BEGIN PROGRAM.
vardict = spssaux.VariableDict(pattern="^servicedate") for v1 in vardict.range(): spss.Submit("""
IF
(%(v1)s >= EpisodeDate AND %(v1)s <= EpisodePlus3Date) DispensingEventMatch
= 1. """ % locals())
>>>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
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.
|
Free forum by Nabble | Edit this page |