Save datafilename as a string variable

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

Save datafilename as a string variable

Eero Olli
LISTSERV at the University of Georgia

Dear list,

 

I have again a simple question, I hope someone has a simple answer to. How can I save filename of the active dataset as the content of a string variable with syntax or python? I can close all other datasets, so only one dataset is active, if that makes it any easier.

 

I am running tests on a large set of datafiles, and I am saving the test results as a new data file. Therefore, I want a foolproof method of identifying the data file, the test results are referring to. I am not interested in the name of the dataset, only in the actual filename used for .sav file.  I am using SPSS v19.

 

I have tried to capture the datafile name inside a large syntax, but this results in an empty set. I think I am on a wrong track here.

BEGIN PROGRAM PYTHON.

import spss

print "looking for datafileatributes"

try:

    # Build a Python dictionary of the datafile attributes

    attrDict = {}

    for name in spss.GetDataFileAttributeNames():

        attrDict[name] = spss.GetDataFileAttributes(name)

        print attrDict[name]

except:

    print "problem with finding attributes"

 

print "datafileatributenames"

try:

    fileattrs = spss.GetDataFileAttributeNames()

    print fileattrs

 

except:

    print "problem with finding attribute names"

 

END PROGRAM.

 

 

 

_____________________________________________________________

Eero Olli                                                                              

Senior Advisor                                                                [hidden email]

Equality and Anti-discrimination Ombud                    Phone: +47 2315 7344 

Mail: Postboks 8048 Dep, N-0031 Oslo, Norway         Visitors: Mariboesgt 13



Reply | Threaded
Open this post in threaded view
|

Re: Save datafilename as a string variable

Jon K Peck
There is a function for this in the spssaux module.  Here is an example:
begin program.
import spss, spssaux
print "datafile name:", spssaux.getDatasetInfo(Info="Data")
end program.

HTH,

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Eero Olli <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 05:19 AM
Subject:        [SPSSX-L] Save datafilename as a string variable
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Dear list,
 
I have again a simple question, I hope someone has a simple answer to. How can I save filename of the active dataset as the content of a string variable with syntax or python? I can close all other datasets, so only one dataset is active, if that makes it any easier.
 
I am running tests on a large set of datafiles, and I am saving the test results as a new data file. Therefore, I want a foolproof method of identifying the data file, the test results are referring to. I am not interested in the name of the dataset, only in the actual filename used for .sav file.  I am using SPSS v19.
 
I have tried to capture the datafile name inside a large syntax, but this results in an empty set. I think I am on a wrong track here.
BEGIN PROGRAM PYTHON.
import spss
print "looking for datafileatributes"
try:
    # Build a Python dictionary of the datafile attributes
    attrDict = {}
    for name in spss.GetDataFileAttributeNames():
        attrDict[name] = spss.GetDataFileAttributes(name)
        print attrDict[name]
except:
    print "problem with finding attributes"
 
print "datafileatributenames"
try:
    fileattrs = spss.GetDataFileAttributeNames()
    print fileattrs
 
except:
    print "problem with finding attribute names"
 
END PROGRAM.
 
 
 
_____________________________________________________________
Eero Olli                                                                              
Senior Advisor                                                                [hidden email]
Equality and Anti-discrimination Ombud                    Phone: +47 2315 7344  
Mail: Postboks 8048 Dep, N-0031 Oslo, Norway         Visitors: Mariboesgt 13


Reply | Threaded
Open this post in threaded view
|

SV: Save datafilename as a string variable

Eero Olli
In reply to this post by Eero Olli

 

Thank you, Jon!

 

I knew it was somewhere, I just did not manage to find it.

 

Best,

Eero

 

_____________________________________________________________

Eero Olli                                                                              

Senior Advisor                                                                [hidden email]

Equality and Anti-discrimination Ombud                    Phone: +47 2315 7344 

Mail: Postboks 8048 Dep, N-0031 Oslo, Norway         Visitors: Mariboesgt 13



 

Fra: Jon K Peck [mailto:[hidden email]]
Sendt: 1. desember 2011 15:25
Emne: Re: Save datafilename as a string variable

 

There is a function for this in the spssaux module.  Here is an example:
begin program.
import spss, spssaux
print "datafile name:", spssaux.getDatasetInfo(Info="Data")
end program.

HTH,

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Eero Olli <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 05:19 AM
Subject:        [SPSSX-L] Save datafilename as a string variable
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





Dear list,
 
I have again a simple question, I hope someone has a simple answer to. How can I save filename of the active dataset as the content of a string variable with syntax or python? I can close all other datasets, so only one dataset is active, if that makes it any easier.
 
I am running tests on a large set of datafiles, and I am saving the test results as a new data file. Therefore, I want a foolproof method of identifying the data file, the test results are referring to. I am not interested in the name of the dataset, only in the actual filename used for .sav file.  I am using SPSS v19.
 
I have tried to capture the datafile name inside a large syntax, but this results in an empty set. I think I am on a wrong track here.
BEGIN PROGRAM PYTHON.
import spss
print "looking for datafileatributes"
try:
    # Build a Python dictionary of the datafile attributes
    attrDict = {}
    for name in spss.GetDataFileAttributeNames():
        attrDict[name] = spss.GetDataFileAttributes(name)
        print attrDict[name]
except:
    print "problem with finding attributes"
 
print "datafileatributenames"
try:
    fileattrs = spss.GetDataFileAttributeNames()
    print fileattrs
 
except:
    print "problem with finding attribute names"
 
END PROGRAM.
 
 
 
_____________________________________________________________
Eero Olli                                                                              
Senior Advisor                                                                [hidden email]
Equality and Anti-discrimination Ombud                    Phone: +47 2315 7344  
Mail: Postboks 8048 Dep, N-0031 Oslo, Norway         Visitors: Mariboesgt 13