Using First & Last variables for SPSS Syntax- Great way to reduce your code

SPSS syntax

In SPSS syntax you can streamline your code by putting the word “TO” between the first and last variable you want.  For instance, in the image below, Category, Lang, cname, Date, and Sent is highlighted. If I wanted to run frequencies perform something on all of these variables I could write the following code:

or I could simply do the following:

Both return the same results yet the second one is much simpler, cleaner and can save a lot of space (especially when there are dozens of variables).

I have a short AutoHotKey script which grabs the variables highlighted, copies them to the clipboard and takes the first item, then puts the word ” TO ” then grabs the list item.

This helps me write clean-looking syntax much faster than doing it manually.

Grabbing first and last variable with SPSS syntax

Grabbing First and Last variables for SPSS Syntax

 

The following is the AutoHotKey code:

 


Leave a Reply