SPSS Syntax - Using File Path

I have a group of SPSS data and syntax files that I move by changing folders on a daily basis. However, the relative paths remain unchanged. Is there any way to use this fact? for example: use the INCLUDE command and specify a syntax file that is always on the same level as the path up; or use GET to open a file located at two levels of UP

Going to the search, I found a link to the HOST command, but I could not get it to work.

Any input would be appreciated :)

Thank you very much in advance

+3
source share
2 answers

You can get the relative path of the SPSS syntax (provided it is saved) using python.

SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath()

, , pythons os ( ). , . , , , SPSS ( GET, INCLUDE ).

* Run this in any saved SPSS syntax to test *.
begin program.
import spss,spssaux,SpssClient, os
SpssClient.StartClient() 
synPathL0U = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath()) 
SpssClient.StopClient()
synPathL1U=os.path.dirname(synPathL0U)
synPathL2U=os.path.dirname(synPathL1U)
print "synPathL0U =",synPathL0U
print "synPathL1U =",synPathL1U
print "synPathL2U =",synPathL2U
spss.SetMacroValue("!synPathL0U",spssaux._smartquote(synPathL0U+"\\"))
spss.SetMacroValue("!synPathL1U",spssaux._smartquote(synPathL1U+"\\"))
spss.SetMacroValue("!synPathL2U",spssaux._smartquote(synPathL2U+"\\"))
end program.

/* Check results - Echo should relay back the desired folder paths */.
echo !synPathL0U.
echo !synPathL1U.
echo !synPathL2U.

, , .

BEGIN PROGRAM/END PROGRAM Run(args) python, , , SET_JOB_CWD.py. , , .

, SET_JOB_CWD.py :

def Run(args):
   import spss,spssaux,SpssClient, os
   SpssClient.StartClient() 
   synPathL0U = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath()) 
   SpssClient.StopClient()
   synPathL1U=os.path.dirname(synPathL0U)
   synPathL2U=os.path.dirname(synPathL1U)
   spss.SetMacroValue("!synPathL0U",spssaux._smartquote(synPathL0U+"\\"))
   spss.SetMacroValue("!synPathL1U",spssaux._smartquote(synPathL1U+"\\"))
   spss.SetMacroValue("!synPathL2U",spssaux._smartquote(synPathL2U+"\\"))

SET_JOB_CWD.xml , :

<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SET JOB CWD" Language="Python">
</Command>

, ( , SHOW EXTPATHS. SPSS, , "EXTPENHS EXTENSIONS", - .

, SPSS. SET JOB CWD., SPSS !synPathL0U, !synPathL1U, !synPathL2U, , .

+4

v21 () Python . v22.

Python R Essentials , , . STATS OPEN PROJECT. .

v21-22 - SPSS. .

INCLUDE, BTW. INSERT. .

+1

Source: https://habr.com/ru/post/1664651/


All Articles