JonathanGall
JonathanGall

Reputation: 17

Can I tell SPSS to run certain syntax lines using a syntax command?

So I was wondering if it was possible to write something up in the syntax which tells the program to run certain command lines. I'm not very good at explaining, so here's an example:

*Total sample frequency.
    FREQUENCIES VARIABLES=Age Gender CigDay CO Min_last Day_abs Cigs_Monthly
       /ORDER=ANALYSIS.

*6. Next, using the split-file function, perform the frequency analysis for each gender.

* Split file.
    SORT CASES  BY Gender.
    SPLIT FILE LAYERED BY Gender.

*7 Run frequency again. 
    FREQUENCIES VARIABLES=Age Gender CigDay CO Min_last Day_abs Cigs_Monthly
       /ORDER=ANALYSIS.

So, I was wondering whether it was possible to not have to copy/paste the Frequency command and simply include a line of command that told SPSS to re-run the syntax rows 37 to 38 (Which is where the first frequency command written).

Upvotes: 0

Views: 536

Answers (2)

djhurio
djhurio

Reputation: 5536

A short answer is - no. There is not a command available that would allow to run a specific line of syntax. Certainly you can do it manually by selecting and running the lines you need.

But there are other options available for such tasks when you need to re-run a part of the code several time:

  • Insert command. Save the code you need to run several time in an external syntax file and insert it when needed in your main syntax file.
  • Define and End Define commands. Define the code you need to run several time as a macro command and call it when needed in your main syntax file.

Upvotes: 2

JKP
JKP

Reputation: 5417

I suggest not using INCLUDE as it is obsolete, although it is still supported. INSERT provides better functionality.

If you set out to build a macro library for your frequently used commands, think about parameterizing them so that, for example, you can pass in the specific variables to use as arguments. See the Command Syntax Reference entry for DEFINE via the Help menu for full details, but be prepared to spend some time studying it.

Upvotes: 0

Related Questions