Domanda

In SPSS 11 è stato possibile specificare i percorsi relativi. Esempio:

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

Questo ha funzionato perché a quanto pare, SPSS 11 impostare la cartella di lavoro per il percorso in cui è stato salvato il file di origine .SPS. Sembra che SPSS 18 imposta sempre cartella di lavoro è di nella cartella di installazione di SPSS per sé. Il che non è affatto la stessa cosa.

C'è un'opzione per modificare questo comportamento? O sono bloccato con il cambiamento di tutto per i nomi di file assoluti?

È stato utile?

Soluzione

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)

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top