Hi,
I'm trying to manipulate SPSS variable names. When I start SPSS, open a data file and run the following code in a syntax window, everything works fine.
BEGIN PROGRAM . import spss
N =spss.GetVariableCount() for i in range(N): print spss.GetVariableName(i) END PROGRAM .
However, when I copy the exact same code (minus BEGIN/END PROGRAM) to my Python IDE it doesn't work. My IDE works fine but somehow the code above is not "connected" to the open dataset. It returns empty... I must be missing some fundamentals?
Also, I've been much helped by "Python Scripting Guide for IBM SPSS Statistics" but I can't find anything on the "spssaux" and "spss" python modules. Is there such a document?
Answer by LazerGuidedStefan (1) | Jan 22, 2015 at 04:16 PM
The thing is that there is no .sav file to get. I have a lot of project folders where .sps and *.dat files live. So I loop over the folders, and run the syntax via SpssClient.RunSyntax(). When done, I want to check if the data file actually contains a few variable names. If the file doesn't contain them, I don't want to save the file...
My current approach is to read the DATA LIST command from the *.sps file and check the list of variable names for the occurrence of my mandatory variables. If I don't find them, I don't save the file. This is actually a better solution 'couse I don't need to read the entire data file into memory before checking.
Answer by LazerGuidedStefan (1) | Jan 22, 2015 at 07:31 PM
I'll try the spss.Submit. Should I stick to the spss module, and not involve SpssClient? Is there any rule of thumb on when to use either of them?
And again, is there any documentation on the spss module? I can't seem to find any. Something like "Python Scripting Guide for IBM SPSS Statistics" would be nice!
Rotate Inner Column Labels 2 Answers
Python IDE 2 Answers
Scoring a new data file with PLS 2 Answers
MODIFY TABLES fails when used twice on same table 3 Answers
Deleting/Hiding certain SPSS Pivot Tables with Python 6 Answers