Find Dataset name in Python

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

Find Dataset name in Python

Eero Olli
Hi all,
 
I am looking for a way to find the name of active dataset in Python. I
am using SPSS v15.
 
I am trying make a small python program that does a set of
transformations: Take original dataset, make a copy, calculate cutpoint
values and save these to a .sav,  match files to a temporary dataset-
and if everything looks fine, rename this temporary dataset back to the
original dataset. In effect this would be similar to just adding a few
new variables to the original datafile.  (or perhaps use a new name for
the dataset, and close the original dataset, but this limits the
usability of this).  Now all my transformations are working, but I would
like to add a better controll of dataset used.
 
I have tried both OMS and spss.GetDataFileAttributes(name) without
getting the name of the dataset.
 
BEGIN PROGRAM PYTHON.

import spss

""" Trying to find out the name of the dataset"""

for name in spss.GetDataFileAttribute(name):

   print spss.GetDataFileAttributes(name)

END PROGRAM.

 

Any advice is appreciated. Perhaps there is an other road that leads to
the same result?

Sincerely,

Eero Olli

________________________________________
Eero Olli
Advisor
the Equality and Anti-discrimination Ombud
[hidden email]                   +47 2405 5951
POB 8048 Dep,     N-0031 Oslo,      Norway
 

====================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: Find Dataset name in Python

Peck, Jon
The file name for the active dataset, assuming it has one, can be obtained with the getDatasetInfo api in the spssaux module (as well as other information).  This will work in any version of programmability.  (Version 16 has additional api capabilities in this area.)

Look at the docstring of this api for details.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eero Olli
Sent: Monday, November 03, 2008 8:49 AM
To: [hidden email]
Subject: [SPSSX-L] Find Dataset name in Python

Hi all,

I am looking for a way to find the name of active dataset in Python. I
am using SPSS v15.

I am trying make a small python program that does a set of
transformations: Take original dataset, make a copy, calculate cutpoint
values and save these to a .sav,  match files to a temporary dataset-
and if everything looks fine, rename this temporary dataset back to the
original dataset. In effect this would be similar to just adding a few
new variables to the original datafile.  (or perhaps use a new name for
the dataset, and close the original dataset, but this limits the
usability of this).  Now all my transformations are working, but I would
like to add a better controll of dataset used.

I have tried both OMS and spss.GetDataFileAttributes(name) without
getting the name of the dataset.

BEGIN PROGRAM PYTHON.

import spss

""" Trying to find out the name of the dataset"""

for name in spss.GetDataFileAttribute(name):

   print spss.GetDataFileAttributes(name)

END PROGRAM.



Any advice is appreciated. Perhaps there is an other road that leads to
the same result?

Sincerely,

Eero Olli

________________________________________
Eero Olli
Advisor
the Equality and Anti-discrimination Ombud
[hidden email]                   +47 2405 5951
POB 8048 Dep,     N-0031 Oslo,      Norway


=======
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
Reply | Threaded
Open this post in threaded view
|

Re: Find Dataset name in Python

Garry Gelade
In reply to this post by Eero Olli
Dear Eoro

I'm happy to pass on this solution from John Peck:

myname=spssaux.GetActiveDatasetName()

It works in SPSS 15.

I must admit I find it difficult to discover this sort of fairly basic thing
from the documentation/module code. And Raynald Levesque's book, while very
useful is not an exhaustive source.  Maybe SPSS will produce something
eventually?


Garry Gelade
Business Analytic Ltd


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Eero Olli
Sent: 03 November 2008 15:49
To: [hidden email]
Subject: Find Dataset name in Python

Hi all,

I am looking for a way to find the name of active dataset in Python. I am
using SPSS v15.

I am trying make a small python program that does a set of
transformations: Take original dataset, make a copy, calculate cutpoint
values and save these to a .sav,  match files to a temporary dataset- and if
everything looks fine, rename this temporary dataset back to the original
dataset. In effect this would be similar to just adding a few new variables
to the original datafile.  (or perhaps use a new name for the dataset, and
close the original dataset, but this limits the usability of this).  Now all
my transformations are working, but I would like to add a better controll of
dataset used.

I have tried both OMS and spss.GetDataFileAttributes(name) without getting
the name of the dataset.

BEGIN PROGRAM PYTHON.

import spss

""" Trying to find out the name of the dataset"""

for name in spss.GetDataFileAttribute(name):

   print spss.GetDataFileAttributes(name)

END PROGRAM.



Any advice is appreciated. Perhaps there is an other road that leads to the
same result?

Sincerely,

Eero Olli

________________________________________
Eero Olli
Advisor
the Equality and Anti-discrimination Ombud
[hidden email]                   +47 2405 5951
POB 8048 Dep,     N-0031 Oslo,      Norway


=======
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

__________ NOD32 3578 (20081103) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com

=====================
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