- So, how do I dig into this Python stuff once everything is installed?
For learning the Python language, a good place to start is the official Python tutorial at http://docs.python.org/tut/tut.html.
Another good tutorial for beginners is http://www.byteofpython.info.
For experienced programmers, look at Dive Into Python.
For understanding how to work with IBM SPSS Statistics using Python, navigate to Integration Plug-In for Python Help>Python Integration Package for IBM SPSS Statistics, in the IBM SPSS Statistics Help system (accessed from Help>Topics). The documentation is available once the IBM SPSS Statistics – Integration Plug-In for Python is installed. A PDF version of the documentation is available from Help>Programmability>Python Plug-in.
For using the supplementary Python modules available from the SPSS group on IBM My developerWorks, start with the spssaux module, which is installed with the Integration Plug-In for Python for version 16 or higher of the plug-in. Examples of working with the spssaux module can be found in Programming and Data Management for IBM SPSS Statistics. You may also find the article Programmability in SPSS Statistics 17 (available on this site) useful.
- What happened to the SPSS Developer Central site?
The SPSS Developer Central site was shut down on May 2, 2011. All the previous contents were migrated to this site except for a small number of obsolete items.
- I have installed the R Essentials for my version of Statistics on Windows, but I don’t see any output from R extensions or programs.
First, be sure that you have installed the appropriate version of the R Essentials. You need to install the appropriate version of R first.
Next run this program to see if the connection is working at all.
BEGIN PROGRAM R.
If the connection to R is working, you will see an R window pop up. You can type R statements there. Type Q to close the window. If you don’t see this window, check that you have installed the correct version of R and of the R Essentials.
If you pass that test, and you are on Vista or Windows 7, it is likely that the Essentials were installed incorrectly. Follow these steps to fix it.
– Run the Essentials installer again and choose Remove or go to the Control Panel>Add Remove Programs and remove it that way
– Run the Essentials installer by right clicking on the executable and choosing Run as Administrator
- I know I need to install R before installing the R Extensions, but I can’t find the right R version. How can I find it?
First, do read the installation instructions for the R Essentials.
You need to be sure to get the right version of R. It changes with each version of Statistics and may vary with the platform. For Statistics 20, R2.12.1 is required for most platforms. You get R itself from the CRAN site. Once there, you need to find the right R version. For Windows, Mac, and Linux, follow the link Download R for …
Next, click on Base and then on Previous Releases if the version you need is not the latest one. Pick the right one from the long list that appears.
For Mac, the page contains an Old link to the previous versions.
The Linux link branches by distribution before getting to the version tree.
- I can’t install the programmability Essentials, a custom dialog box, or an extension command, because I don’t have write access to the required location. What can I do?
By default, custom dialogs and extension commands are installed in directories under the IBM SPSS Statistics installation directory. On some operating systems, including Windows Vista and Windows 7, the default installation location is under Program Files, and you may need extra permission to write to that location. Other operating systems may have a similar problem.
For the Essentials, If you have sufficient permissions on Vista or Win 7, right click the Essentials executable and choose Run As Administrator.
For custom dialogs and extension commands, you can create environment variables named SPSS_CDIALOGS_PATH and SPSS_EXTENSIONS_PATH that identify one or more locations where you do have write permission. SPSS Statistics will look there before looking in the default locations.
To create an environment variable on Windows (the exact wording varies slightly on different Windows versions). open the Control Panel from the Start menu. Then, on XP, choose System, Advanced, Environment Variables. On Windows 7, this is Control Panel, System and Security, System, Advanced, Environment Variables. Create user or system variables with the names above and specify the full path to an existing location where you have write permission. Save it and restart SPSS Statistics if it is already running.
One user on Win 7 reported that he had to turn off the Win 7 UAC in order to get the install to work.
- I am running on Windows 7 or Vista, and I can’t read the help for Basic scripting. What can I do?
In order to read the Basic help, you need to install winhlp32.exe from Microsoft. You can find it here. Microsoft does not provide it automatically on Windows 7 or Vista, and they do not permit developers to ship this file, but they do provide it as a user download.
- I want to run PLS, but I can’t find the required numpy and scipy libraries. What can I do?
The PLS procedure requires the Python numpy and scipy libraries. For most platforms and Python versions, they can be found here (numpy) and here (scipy). But 64-bit Windows binaries require more digging, because of Intel library licensing issues. Unofficial 64-bit versions can be found here. Although they refer to amd64, they should work fine on Intel, too. While IBM does not endorse or support these libraries, it appears from light testing that they work properly for the purposes of the PLS procedure.
- I want to pass parameters to Python on the BEGIN PROGRAM command, but it does not allow this. What can I do?
First, consider converting the program into an extension command. These can take parameters in the regular SPSS Statistics syntax style. And there is an extension command called SPSSINC PROGRAM that makes it very easy to convert a program into an extension command if you don’t want to build a full fledged command.
BEGIN PROGRAM does not accept parameters, but there is an easy way to achieve this. Suppose you have IBM SPSS Statistics code such as a macro that you want to convert to Python, and it has parameters. First, rewrite the macro as a Python function, say, f(x,y,z).
body of the function
Second, save this in a module on the Python search path. You might build a library of functions and keep them in mylib.py. To use this converted function, you would simply call it in BEGIN PROGRAM, passing parameters as needed.
In other words, the parameters are used similarly to IBM SPSS Statistics macro call parameters but written in Python syntax.
You might, though, need to generate the parameter values with IBM SPSS Statistics syntax that is not already in a BEGIN PROGRAM block. It is easy to convert an IBM SPSS Statistics syntax job into a BEGIN PROGRAM stream, and then you can easily use the Python function call approach. To read about how to do this, see the article on this site called Converting an IBM SPSS Statistics Syntax Job to a Python job. It is easier than you think!
- I have downloaded a module, but when I import it in IBM SPSS Statistics, I get the error “No module named …” Why?
Downloaded modules need to be saved in one of the places where Python looks for imports. See the article How to Use Downloaded Python Modules (available on this site) for solutions.
- I have modified a module and reimported it, but my program behavior did not change. What is wrong?
Running an import statement does not refresh a module that is already loaded. Use
reload(modname) to bring in the latest version.
If you have more than one copy of a module on the Python search path, the wrong one might be loaded (your process working directory is automatically on the path). Use the statement:
in your program to see where the module was loaded from.
- I have a long Python list and would like to display each item as a separate line in the Viewer. How do I do this?
You can make long Python lists display each item on a separate line with code like this.
This combines the items in the list alist into a string with a line break between each one.
- I have done some calculations in Python and would like to display them as a pivot table? Can I do this?
You can use the BasePivotTable class in the spss module (available for SPSS 15 or later). If your pivot table only contains one row dimension and one column dimension then consider using the SimplePivotTable method in the BasePivotTable class. You can also create Viewer text blocks using the spss.TextBlock class.
- I want to run a procedure only if a particular variable exists in the current dataset. Is there an easy way to check this?
Here is some program code that runs the FREQUENCIES procedure on variable x only if it exists.
import spss, spssaux
vardic = spssaux.VariableDict()
spss.Submit("FREQ " + vardic['x'].VariableName)
The variable vardic gets a list of all the variables in the IBM SPSS Statistics dictionary.
vardic['x'].VariableName evaluates to the name, x, if x exists; otherwise it raises an exception. In this example, the exception does nothing.
- I’m trying to use an extension command, and I get an error message that it cannot be loaded. I have the files in the right place. What could be wrong?
First, be sure the files associated with the extension command are in the correct location. Extension commands require SPSS 16 or later. They consist of two files–an XML file that specifies the syntax of the command and a code file (a Python module, R source file or R package) that implements the command.
For SPSS 16, the XML file goes in the extensions subdirectory of the SPSS 16 installation and the code file goes where Python or R can find it. For example, for Python, it might be placed in c:\python25\lib\site-packages if Python was installed in the default location.
For SPSS Statistics 17 and higher, both files go in the extensions subdirectory of the IBM SPSS Statistics installation. If the extension command is installed as part of an extension bundle (available with version 18 and higher), then the files are automatically placed in the proper location.
Note: For Mac, the IBM SPSS Statistics installation directory refers to the Contents directory in the SPSS Statistics application bundle. For version 18 and higher for Mac, the files can also be placed in the /Library/Application Support folder. See the topic “Deploying an Extension Command” in the article Writing IBM SPSS Statistics Extension Commands (available on this site) for detailed information.
If the extension command files are in the correct location, then errors in the implementing Python module or missing or out-of-date modules that the implementing module requires can cause it to fail to load. To diagnose the problem, start Python from a DOS command line–for example,
c:\python26\python–and enter this line:
where modname is the name of the module. The error messages displayed should identify the specific problem preventing loading.
- I’m installing the Integration Plug-In for Python for PASW Statistics 18 or IBM SPSS Statistics 19 and the installation instructions state that either Python 2.6.2 or 2.6.4 is recommended but I only see Python 2.6.5 on www.python.org. Will Python 2.6.5 work?
Yes, you can install Python 2.6.5 instead of 2.6.2 or 2.6.4.
- I installed an extension command such as SPSSINC MODIFY TABLES, but I get an error message like spssinc. The first word in the line is not recognized ….
In order for an extension command to be recognized, you must ensure that the xml file in the package, e.g., SPSSINC_MODIFY_TABLES.xml, is placed in the extensions subdirectory of your SPSS Statistics installation and SPSS Statistics is restarted. If you installed an extension bundle, this is taken care of automatically, but for an spd file you must do this manually.
If you do not have write access to this directory (especially on Vista if Statistics is installed under Program Files), you can create an environment variable named SPSS_EXTENSIONS_PATH with contents a directory or semi-colon separated list of directories where extensions may be found.
If, however, the message is a complaint that the extension code cannot be loaded or a BEGIN PROGRAM failure, you might not have the plugin installed, or you might not have the Python or R files installed in the right place.
- I’m installing R Essentials or the R Plug-in and the installation instructions tell me to download a particular version of R but I can’t find that version on the R site.
You can find older versions of R at the following locations:
Linux and UNIX: ftp://ftp.stat.math.ethz.ch/Software/CRAN/src/base/R-2/
Finding that older version takes a little digging. Here is how you would do it for Windows, starting from the CRAN site.
Click on these links:
-Download R for Windows
-R2.10.1 (or whatever release is required)
- I’m installing Essentials for Python on Mac Lion (OS X 10.7) but the installation instructions don’t specifically mention Lion. Is there anything special I need to do?
Installing Essentials for Python on Mac Lion is particularly straightforward because Python 2.7 is pre-installed on Lion, so there is no need to separately download and install Python 2.7. During the installation of Essentials for Python, you will be prompted for the location of the Python 2.7 folder. Simply accept the default value of /usr.