Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

Problems getting variable names

270004QUB3 gravatar image
Question by LazerGuidedStefan  (1) | Jan 22, 2015 at 11:30 AM spssstatisticsextensibilitypython

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?
 

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

13 answers

  • Sort: 
270004QUB3 gravatar image

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.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002VCWN gravatar image

Answer by JonPeck (4671) | Jan 22, 2015 at 04:52 PM

I would use spss.Submit rather than RunSyntax just to make sure that there isn't a synchronization issue. If the Get apis are not returning anything, then the dataset hasn't been created yet.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270004QUB3 gravatar image

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!

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • ‹
  • 1
  • 2

Follow this question

46 people are following this question.

Answers

Answers & comments

Related questions

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

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges