Specifying relative paths in SPSS 18

≡放荡痞女 提交于 2019-12-14 03:52:47

问题


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:


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)




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/2966177/specifying-relative-paths-in-spss-18

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!