在 SPSS 18 中指定相对路径

发布于 2024-09-04 05:50:23 字数 290 浏览 2 评论 0原文

在 SPSS 11 中可以指定相对路径。示例:

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

这之所以有效,是因为 SPSS 11 将工作文件夹设置为保存源 .SPS 文件的路径。看来SPSS 18总是将其工作文件夹设置为SPSS本身的安装文件夹。这根本不是一回事。

有没有办法改变这种行为?或者我是否坚持将所有内容更改为绝对文件名?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如若梦似彩虹 2024-09-11 05:50:24

如果您使用 INSERT 命令运行 sps 文件,它可以选择将工作目录更改为该位置。

您可以使用 HOST 命令替换驱动器号(在 PC 上)并通过该命令引用所有内容。

您可以将文件句柄定义到公共根位置并在文件引用中使用它。

您可以使用 Python 可编程性来查找活动语法窗口的路径,并发出 SPSS CD 命令来适当地设置后端工作目录。

哈特哈,
乔恩·佩克

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

累赘 2024-09-11 05:50:24

使用Python,您可以获得当前语法窗口(或任何其他窗口)的完整路径并获取其路径。使用它,您可以发出 SPSS cd 命令来相应地更改后端工作目录。

不过,如果您定义了环境变量,则可以在 SPSS 内的文件规范中使用它。

ps SPSS 拥有大量适用于 Python(以及 R 和 .NET 语言)的 api 和帮助程序模块。您可以从 SPSS Developer Central(www.spss.com/devcentral)获取相关信息。一旦您拥有基础 SPSS Statistics 产品,所有语言扩展都是免费的。

问候,
乔恩·佩克

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

邮友 2024-09-11 05:50:24

或者使用“CD”命令更改默认工作目录。另请参阅:

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

例如,如果您的默认目录是 C:\project,则 GET FILE 'data\data_file.sav'。将从 C:\project\data 打开 data_file.sav。

然后,几分钟后,我发现了这个来自 jignesh-sutar 的小 python 脚本(请参见此处:< a href="https://stackoverflow.com/questions/28010865/spss-syntax-use-path-of-the-file">SPSS 语法 - 使用文件路径

通过他的 python 代码,您可以 。使用语法文件的路径作为语法中所有路径的起点。

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.

春庭雪 2024-09-11 05:50:23

您可以定义一个目录路径,并在其他文件句柄声明中使用它来代替相对路径,以节省键入:

FILE HANDLE directoryPath /NAME='C:\Directory\Path\' 。
文件句柄 myFile /NAME='directoryPath/fileName.xyz' 。
获取文件='myFile'。

这将获取文件:C:\Directory\Path\fileName.xyz。

斜线的方向可能很重要。

(适用于版本 17)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文