views:

152

answers:

3

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?

+1  A: 

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

Jon Peck
what? Python support?! Funky... I don't have much experience in SPSS. Python on the other hand... :) I'm certainly going to have a look at that.
exhuma
After having a first look, python does not seem to be a satisfactory answer. I'm going to look at environment variables next. Thinking that `COMPUTERNAME` might be helpful. `SHOW ENVIRONMENT.` displays the variables, but how can I get to one of them?
exhuma
+1  A: 

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

Jon Peck
Thanks for the link to devcentral. Unfortunately I currently have to look into other things. I'll give it a try as soon as I get some spare time.
exhuma
+1  A: 

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)

Alaska
Thanks for the reply. I am already using this as a workaround.
exhuma