• Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey GUIs are Easy with AutoHotkey Intro to DOS & AutoHotkey

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:

Frequency Category Lang cname Date Sent.

or I could simply do the following:

 Frequency Category TO Sent.

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

 

The following is the AutoHotKey code:

 
;************************Grab first and Last variables for SPSS syntax*******************************.
^!v:: ;Control Alt V is the hotkey that pastes what is on the clipboard
Loop, parse, Clipboard, `n, `r ; Specifying `n prior to `r allows both Windows and Unix files to be parsed.
{
If A_Index =1
First:=A_LoopField
Last:=A_LoopField
}
FirstToLast:= " " . First . " TO " . Last . " "
SendPlay, %FirstToLast%
return

 


SPSS to Excel graph in seconds– Autographs to reduce workload

SPSS to excel graph

Typically I used to use SPSS to create tables then export them and graph them in Excel (because Excel makes darn pretty graphs!)

A few years back I wrote a script that would, automatically, take SPSS tables and create the graphs for me.  This brought down my reporting time to minutes instead of hours!  Using AutoHotKey I was able to take SPSS to Excel without embedding any macros.  This is possible because AutoHotKey can connect via a COM object.

SPSS to Excel graph in seconds

 

 

SPSS macro – Repurposing the file path for multiple uses

SPSS macro
I write a TON of SPSS code and work with colleagues around the world as well as on different computers which have different drives – paths available. This SPSS macro shows how you can get around a lot of the headaches dealing with these issues.  There are some other SPSS commands that can be used similarly however I find this exceptionally helpful as I can reference it when I’m merging files, exporting to text / Excel, saving output, etc.

SPSS macro

 
/***********************Save file macro********************************.
Define !Sav (File=!TOKENS(1)) Save OutFile=!path+!file+'.sav' /Compressed. !enddefine.

/***********************Get file and show N********************************.
Define !Get (File=!TOKENS(1))
Get File=!path+!file+'.sav'. 
DATASET NAME $DataSet WINDOW=FRONT.
exe.
show n.
!enddefine.

 

SPSS missing values & corresponding “missing” syntax to solve your needs

SPSS missing values

SPSS missing values

The syntax around SPSS variables with missing values is not intuitive, confusing, and poorly documented!

I know of 3 different types of commands and knowing which one to use when is not clear.  Setting SPSS missing values is a great way to simplify your analysis.  It is also a user-friendly way to remove (hide) outliers.  This video gives a short demo of how to use the three that I use frequently.

 

If you want to declare a value in a cell as missing the following syntax will give you a good start.

 if   Var1=1  Var1=$sysmis.
exe.

 

If you want to remove the values that are in a variable (define them as missing) the following syntax will be what you need.

 MISSING VALUES Var1 to Var10 (99).

 

SPSS missing values Macros

Below are two macros to help with missing data.  The first one is used when you first want to see if there is a given value present in another variable before declaring it recoding the missing a zero.  The second one will recode all variables with missing values a zero.

 
*///////////////.
DEFINE !Rep_Miss (Beg !TOKENS (1) /Prez !TOKENS (1) /End !TOKENS (1))
Do if !PREZ>0.
do repeat v=!BEG to !END.
if missing (v) v=0.
end repeat.
end if.
exe.
!ENDDEFINE.
*///////////////.

!Rep_Miss Prez=presentvariable Beg=v11 End=v19.

*///////////////.
DEFINE !Rep_Miss2 (Beg !TOKENS (1) /End !TOKENS (1))
do repeat v=!BEG to !END.
if missing (v) v=0.
end repeat.
exe.
!ENDDEFINE.
*///////////////.
/*!Rep_Miss2 Beg=v11 End=v19.
  • Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey GUIs are Easy with AutoHotkey Intro to DOS & AutoHotkey