Reputation: 323
Currently I save files to the absolute file path SAVE OUTFILE='my/path/to/file.sav'
. This is not optimal, so I would like to save files to dynamic/relative file paths like SAVE OUTFILE='file.sav'
.
So I need to set current directory, but this works as above as well CD 'my/path/to/'
and then save. But I am wondering if SPSS can't set directory automatically when opening files? We are usually a lot of people working with same syntaxes and we will always have to change the absolute file paths.
Edit: As Jignesh Sutar have stated I can as well use python extension. So I thought I could use something simple like:
BEGIN PROGRAM.
import spss,spssaux, os, SpssClient
SpssClient.StartClient()
path = SpssClient.GetCurrentDirectory()
print path
spss.Submit(r"""CD = '%s'.""" % (path))
SpssClient.StopClient()
END PROGRAM.
But above will actually just output the script and nothing else, however, another simple case would be:
BEGIN PROGRAM.
import spss
firstvar=spss.GetVariableName(0)
print firstvar
END PROGRAM.
And this is indeed working fine.
Upvotes: 4
Views: 1833
Reputation: 5417
Another possibility is to use the STATS OPEN PROJECT extension command. This opens a project and carries out the actions it defines. It can open data files, run any syntax, etc. You can have a master project that does things you always want and subprojects for specific work. It can be set to do this on Statistics startup if you want.
STATS OPEN PROJECT can be installed from the Extensions menu in V24 or Utilities > Extension Commands in V22 or 23.
Upvotes: 1
Reputation: 2929
SPSS has a FILE HANDLE
and CD
command (as you point out also) that aid to try make these type of thing easier.
However I opt for a different approach that I have all my job setup to use, which if you use Python can implement also.
You can get the dynamic location of a (saved) syntax file using python like so:
os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
I have posted a detailed solution to this in the past which you can find here and may find helpful in your scenario also.
Upvotes: 4