Jeromy Anglim
Jeromy Anglim

Reputation: 34947

How to source a syntax file from another syntax file in SPSS?

In R there is the source function where you can source an R script from another R script. I want to be able to do the same in SPSS.

How can I source an SPSS syntax file from another SPSS syntax file?

Upvotes: 3

Views: 5023

Answers (1)

Jeromy Anglim
Jeromy Anglim

Reputation: 34947

Updated Following @AndyW's comments.

There is the INSERT and INCLUDE commands. INSERT is newer and more versatile than INCLUDE. See documentation on INSERT here.

The following is the basic syntax template:

INSERT  FILE='file specification'
       [SYNTAX = {INTERACTIVE*}]
                 {BATCH       }
       [ERROR = {CONTINUE*}]
                {STOP     }
       [CD = {NO*}]
             {YES}
       [ENCODING = 'encoding specification']

Thus, the following command can be placed in an SPSS syntax file

INSERT FILE='foo.sps'. 

and it would import foo.sps syntax file. By default, syntax must follow the rules of interactive mode, and the code wont stop on an error.

To avoid having to specify the full path to the file, the working directory can be specified as an argument in the INSERT statement or with a separate CD command. E.g.,

CD '/user/jimbo/long/path/to/project'

Another option is to use FILE HANDLE.

For more information see the SPSS Syntax Reference (available here as a large PDF file).

Upvotes: 7

Related Questions