SPSS tutorials website header logo SPSS TUTORIALS BASICS ANOVA REGRESSION FACTOR CORRELATION

SPSS CD Command

A best practice in SPSS is to open and save all files with syntax. Like so, it can be easily seen which syntax was run on which data. One could use the syntax generated by Paste for this but there's a much shorter and better option.

Disadvantages of the Default Syntax

Each time you open a data file from the GUI, SPSS generates syntax that may look something like
GET FILE='C:\Documents and Settings\Work\Projects 2012\December\Some Customer\Survey data.sav'.
This exact specification of the folder and the file name is known as a absolute path. Using absolute paths has two disadvantages.

Shortening the Syntax

The default syntax can basically be broken up into two parts: a folder specification and a file specification. The point here is that the folder specification is needed only once during a session. The syntax below demonstrates the idea.
*Set working directory.

cd 'C:\Documents and Settings\Work\Projects 2012\December\Some Customer'.

*Open data file.

get file 'Survey data.sav'.

How Does it Work?

The CD command sets a default directory. Whenever you open or save a file, it will be done from/to this directory. In case you're not sure what your default directory is, run SHOW DIRECTORY. In subsequent commands, you only have to type the file name, which is technically a relative path. Especially when you open or save multiple files, you'll need less syntax. More importantly, if you move your project to a different folder, you'll need to adjust only a single line of syntax (the cd command, that is). Especially when a project involves multiple syntax files, this may prove a major advantage, especially when combined with INSERT.

Using Subfolders

Whenever you use relative rather than absolute paths, SPSS quietly prefixes them with the default directory. When you'd like to access a file in a subdirectory of the default directory, you can specify only the subdirectory and the file name.
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.

Final Notes

CD applies to all files such as

except tablelooks (“SET TLOOK ...”). I find this very annoying and I don't see why this hasn't fixed ages ago...

Command Syntax Reference Saying CD does not work for TLOOK

Thanks for reading!

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.

THIS TUTORIAL HAS 16 COMMENTS: