Question

In SPSS 11 it was possible to specify relative paths. Example:

FILE HANDLE myfile='..\..\data\current.txt' /LRECL=533.
DATA LIST FILE=myfile /
...

This worked because apparently, SPSS 11 set the working folder to the path where the source .SPS file is saved. It seems that SPSS 18 always sets it's working folder to the installation folder of SPSS itself. Which is not at all the same thing.

Is there an option to change this behaviour? Or am I stuck with changing everything to absolute filenames?

Was it helpful?

Solution

Instead of a relative path, you could define a directory path and use it inside other file handle declarations to save typing:

FILE HANDLE directoryPath /NAME='C:\Directory\Path\' .
FILE HANDLE myFile /NAME='directoryPath/fileName.xyz' .
GET FILE='myFile' .

This will get the file: C:\Directory\Path\fileName.xyz.

The direction of the slashes may be important.

(Works in version 17)

OTHER TIPS

If you use the INSERT command to run an sps file, it has an option to change the working directory to that location.

You could use the HOST command to SUBST a drive letter (on PCs) and reference everything through that.

You could define a FILE HANDLE to the common root location and use that in file references.

You could use Python programmability to find the path to the active syntax window and issue an SPSS CD command to set the backend working directory appropriately.

HTH, Jon Peck

With Python, you can get the full path of the current syntax window (or any other one) and get its path. Using that you can issue an SPSS cd command to change the backend working directory accordingly.

If you define an environment variable, though, you can use that in file specifications within SPSS.

p.s. SPSS has an extensive set of apis and helper modules for Python (as well as for R and .NET languages). You can get information about this from SPSS Developer Central, www.spss.com/devcentral. All the language extensions are free once you have the base SPSS Statistics product.

Regards, Jon Peck

Or use "CD" command to change your default working directory. See also:

http://www.spss-tutorials.com/change-your-working-directory/

For example, if your default directory is C:\project, then GET FILE 'data\data_file.sav'. will open data_file.sav from C:\project\data.

And then, a few minutes later, i came across this little python script from jignesh-sutar (see here: SPSS syntax - use path of the file.

With his python code you can use the path of the syntax file as starting point for all the paths in your syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top