• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

SPSS Macro is just a String Parser, this video goes over some basic usage

SPSS macro

Even in its simplest form, SPSS macros can save you an amazing amount of time by allowing you to quickly & easily swap-out one text for another. The text can be the name of a variable, the title, the statistical test to be run, etc. This can save an amazing amount of time if used properly.

In the below video gives a good demonstration of how easy it is to utilize them.

SPSS Macro is just a String Parser

https://www.youtube.com/watch?v=jaTfSYgqpoY

SPSS Macros for replacing missing data

SPSS macro

SPSS Macros for replacing missing data

A lot of online vendor tools provide a data value on a multi-select question however they leave the value missing if the respondent didn’t select it. Most of the analysis I want to do needs to have a zero (or some other value) present in order to calculate the statistics correctly.

I wrote a few SPSS Macros that make it very easy to replace the missing values on your data.  Here are the two macros

 
*///////////////.
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.

 

https://www.youtube.com/watch?v=5CBm_F3zBOo

SPSS macro makes for easy splitting of data into separate files of equal numbers

SPSS Macro

SPSS macro

If you frequently need to have your data split into equal groups, this SPSS macro is the way to go!  You can just tell it how many groups you want and the variable you want to create to store group belonging and WHAM!  it randomizes the list and adds a new field showing the groups.

In the code below I show two examples of the SPSS macro.  One that will randomize the group and split it out, the second allows you to use another variable before breaking them into groups (In case you want a certain order to them.)  Both macros greatly reduce the amount of work needed to do in SPSS.

 

https://www.youtube.com/watch?v=UAYxNfqk_zI

 
*/////////////////////.
DEFINE !Rand_Group (Groups !TOKENS (1) / NewVar !TOKENS (1))
Match files file=* / DROP !NewVar.
Compute Rand=RV.UNIFORM(0,1).
SORT CASES BY Rand (A).
compute row=$casenum.
RANK VARIABLES=row (A) /NTILES (!Groups) into !NewVar /PRINT=YES /TIES=HIGH.
Match files file=* /drop row Rand.
VARIABLE LEVEL !NewVar (Nominal).
Var label !NewVar "Random Group".
Val labels !NewVar 1'One' 2'Two' 3'Three' 4'Four' 5'Five' 6'Six' 7'Seven' 8'Eight' 9'Nine' 10'Ten'.
Freq !NewVar.
!ENDDEFINE.
*/////////////////////.
!Rand_Group Groups=10 NewVar=Rand_GP.

/* If you want to first sort them on a variable the below macro will handle that for you.

*/////SPSS macro 2////////////////.
DEFINE !Group (Sorter !TOKENS (1) / Groups !TOKENS (1) / NewVar !TOKENS (1))
Match files file=* / DROP !NewVar.
SORT CASES BY !Sorter (A).
compute row=$casenum.
RANK VARIABLES=row (A) /NTILES (!Groups) into !NewVar /PRINT=YES /TIES=HIGH .
Match files file=* /drop row.
VARIABLE LEVEL !NewVar ( ORDINAL ).
Var label !NewVar "Group".
Val labels !NewVar 1'One' 2'Two' 3'Three' 4'Four' 5'Five' 6'Six' 7'Seven' 8'Eight' 9'Nine' 10'Ten'.
Freq !NewVar.
!ENDDEFINE.
*/////////////////////.
!Group Sorter=numords Groups=10 NewVar=Dec_Frequency.

Learning Macros | Raynald’s SPSS Tools

This page is a simple introduction to SPSS macros. There are several fully (line- by-line) commented examples of macro. Overview of several macro-related …

Generating and grabbing SPSS syntax which is automatically generated

SPSS syntax

Grabbing SPSS Syntax

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!

https://youtu.be/hueApbJDkpo