I’ve asked a few of my colleagues and we estimate that around 90% of SPSS users only use the GUI interface. While the GUI interface has it’s merits (I still use it from time to time) using syntax is one of the best ways to be more productive.
In the below video I demonstrate three ways to get /create SPSS syntax generated by using the GUI interface. This is a great way to begin learning how to utilize code!
The syntax around SPSS variables withmissing 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.
https://www.youtube.com/watch?v=_Q19Bbwq-8Q
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.
Windows autocorrect- Adding HotStrings in AutoHotKey
For about 20 years I loved using autocorrect feature in Word and Excel to help me write commonly used phrases. Unfortunately, at that time, MS office didn’t sync across programs so I had to maintain my list of corrections in each program. Worse yet; I also had to repeat it on every computer that I used.
About a decade ago I read an article which mentioned AutoHotKey had built in “Hotstrings” which provided a similar functionality but would work in any windows program. (AutoHotKey has a ton of other great features but this is the one that has the largest appeal to the most users.)
I think of hotstrings and a windows autocorrect. Used intelligently you can tell the computer when I type a few letters, replace the abbreviation I just typed with a full sentence, paragraph, etc. It is fairly easy to add Hotstrings in AutoHotKey however there is a script which speeds-up the process. The below video walks through the process.