Python Error in PSM

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

Python Error in PSM

Dan Riner
I'm trying to run PSM in SPSS 22 via the extension dialog.  The logistic regression runs fine but I get several errors in the fuzzy matching section of the code.   SPSS is not recognizing variable and dataset names that were (should have been) generated.  It seems like a simple python error but my python knowledge is minimal and I can't track down the error in the generated code.  Below is the code I'm running and the errors:

begin program.
import spss, random
try:
   import FUZZY
except:
   print "This procedure requires the FUZZY extension command which is not installed."
parts = [int(i) for i in FUZZY.__version__.split(".")]
if  parts < [1,3,0]:
   raise EnvironmentError("This procedure requires version 1.3.0 or later of FUZZY")
ds = spss.ActiveDataset()
if ds =="*":
   ds = "D" + str(random.random())
   spss.Submit("DATASET NAME " + ds)
matchgroup = "M" + str(random.random())  #temporary variable
tempdsname = "D" + str(random.random())
try:
   spss.Submit(r"""LOGISTIC REGRESSION VARIABLES feeder_filter_2018_4years
     /METHOD=ENTER var1 var2 var3 var4 var5
     /SAVE=PRED(prop_4year_0).""")
except:
   raise ValueError("Logistic Regression step failed")
spss.Submit(r"""FUZZY BY=prop_4year_0 SUPPLIERID=Alpha NEWDEMANDERIDVARS=propID
GROUP=feeder_filter_2018_4years EXACTPRIORITY=FALSE
MATCHGROUPVAR=%(matchgroup)s FUZZ=0 DS3=%(tempdsname)s
/OPTIONS SAMPLEWITHREPLACEMENT=FALSE MINIMIZEMEMORY=TRUE SHUFFLE=FALSE SEED=2018.
DELETE VARIABLES %(matchgroup)s.
DATASET ACTIVATE %(ds)s.
DELETE VARIABLES %(matchgroup)s.
DATASET COPY prop_4year_0.
DATASET ACTIVATE prop_4year_0.
SELECT IF feeder_filter_2018_4years EQ 1.
DATASET ACTIVATE %(tempdsname)s.
DATASET ACTIVATE prop_4year_0.
ADD FILES /FILE=* /FILE=%(tempdsname)s.
EXECUTE.
DATASET CLOSE %(tempdsname)s.""" % locals())
end program.


ERROR Messages:

Traceback (most recent call last):
  File "<string>", line 37, in <module>
  File "", line 7
    if r'C:\Users
                ^
SyntaxError: EOL while scanning string literal


Warnings
Text: M0.976292944138 Command: DELETE VARIABLES
An undefined variable name, or a scratch or system variable was specified in a variable list which accepts only standard variables.  Check spelling and verify the existence of this variable.
Execution of this command stops.


Warnings
Unknown dataset D0.442194324867.
Execution of this command stops.


>Error # 61 in column 25.  Text: D0.442194324867
>The filename is not valid.
>Execution of this command stops.

>Note # 5145
>The working file has been restored, and subsequent commands may access the
>working file.
Warnings
Text: M0.976292944138 Command: DELETE VARIABLES
An undefined variable name, or a scratch or system variable was specified in a variable list which accepts only standard variables.  Check spelling and verify the existence of this variable.
Execution of this command stops.


[prop_4year_0]
Warnings
Unrecognized dataset name D0.442194324867.
Execution of this command stops.


Traceback (most recent call last):
  File "<string>", line 36, in <module>
  File "C:\PROGRA~1\IBM\SPSS\STATIS~1\22\Python\Lib\site-packages\spss\spss.py", line 1527, in Submit
    raise SpssError,error
spss.errMsg.SpssError: [errLevel 3] Serious error.


Dan

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Python Error in PSM

Jignesh Sutar
Try, at first, replacing backslashes to forward slashes (or double forward slashes) where you have the line of code: r'C:\Users

On 11 February 2015 at 15:46, Dan <[hidden email]> wrote:
I'm trying to run PSM in SPSS 22 via the extension dialog.  The logistic regression runs fine but I get several errors in the fuzzy matching section of the code.   SPSS is not recognizing variable and dataset names that were (should have been) generated.  It seems like a simple python error but my python knowledge is minimal and I can't track down the error in the generated code.  Below is the code I'm running and the errors:

begin program.
import spss, random
try:
   import FUZZY
except:
   print "This procedure requires the FUZZY extension command which is not installed."
parts = [int(i) for i in FUZZY.__version__.split(".")]
if  parts < [1,3,0]:
   raise EnvironmentError("This procedure requires version 1.3.0 or later of FUZZY")
ds = spss.ActiveDataset()
if ds =="*":
   ds = "D" + str(random.random())
   spss.Submit("DATASET NAME " + ds)
matchgroup = "M" + str(random.random())  #temporary variable
tempdsname = "D" + str(random.random())
try:
   spss.Submit(r"""LOGISTIC REGRESSION VARIABLES feeder_filter_2018_4years
     /METHOD=ENTER var1 var2 var3 var4 var5
     /SAVE=PRED(prop_4year_0).""")
except:
   raise ValueError("Logistic Regression step failed")
spss.Submit(r"""FUZZY BY=prop_4year_0 SUPPLIERID=Alpha NEWDEMANDERIDVARS=propID
GROUP=feeder_filter_2018_4years EXACTPRIORITY=FALSE
MATCHGROUPVAR=%(matchgroup)s FUZZ=0 DS3=%(tempdsname)s
/OPTIONS SAMPLEWITHREPLACEMENT=FALSE MINIMIZEMEMORY=TRUE SHUFFLE=FALSE SEED=2018.
DELETE VARIABLES %(matchgroup)s.
DATASET ACTIVATE %(ds)s.
DELETE VARIABLES %(matchgroup)s.
DATASET COPY prop_4year_0.
DATASET ACTIVATE prop_4year_0.
SELECT IF feeder_filter_2018_4years EQ 1.
DATASET ACTIVATE %(tempdsname)s.
DATASET ACTIVATE prop_4year_0.
ADD FILES /FILE=* /FILE=%(tempdsname)s.
EXECUTE.
DATASET CLOSE %(tempdsname)s.""" % locals())
end program.


ERROR Messages:

Traceback (most recent call last):
  File "<string>", line 37, in <module>
  File "", line 7
    if r'C:\Users
                ^
SyntaxError: EOL while scanning string literal


Warnings
Text: M0.976292944138 Command: DELETE VARIABLES
An undefined variable name, or a scratch or system variable was specified in a variable list which accepts only standard variables.  Check spelling and verify the existence of this variable.
Execution of this command stops.


Warnings
Unknown dataset D0.442194324867.
Execution of this command stops.


>Error # 61 in column 25.  Text: D0.442194324867
>The filename is not valid.
>Execution of this command stops.

>Note # 5145
>The working file has been restored, and subsequent commands may access the
>working file.
Warnings
Text: M0.976292944138 Command: DELETE VARIABLES
An undefined variable name, or a scratch or system variable was specified in a variable list which accepts only standard variables.  Check spelling and verify the existence of this variable.
Execution of this command stops.


[prop_4year_0]
Warnings
Unrecognized dataset name D0.442194324867.
Execution of this command stops.


Traceback (most recent call last):
  File "<string>", line 36, in <module>
  File "C:\PROGRA~1\IBM\SPSS\STATIS~1\22\Python\Lib\site-packages\spss\spss.py", line 1527, in Submit
    raise SpssError,error
spss.errMsg.SpssError: [errLevel 3] Serious error.


Dan

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD