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

SPSS macro to flip ordinal variable labels so they graph well in Excel

SPSS macroEven though I do nearly all my analysis in SPSS, I still prefer to use Excel to graph my data.  Unfortunately Excel inverts the legend when graphing. Creating a new variable, or re-coding the old one, is time consuming and errors can creep in. This SPSS macro to invert an ordinal variable with very little work.  Saves an amazing amount of time!

It also has a built-in way to filter out too small a sample size.


DEFINE !ISubgp  (Var !TOKENS (1) /Cut !TOKENS (1) )
Select if Sub_CT >=!Cut.
if missing(Subgroup) Sub_CT=$Sysmis.
Freq SubGroup.
!ISubgp Var=Var_toInvert   Cut=20 . 

SPSS macro

The below video demonstrates the usage of the SPSS macro.


Intro to SPSS Macro call; The lifesavers of redundant code

SPSS macro
Using SPSS Macros can save an incredible amount of time.  They have a somewhat-steep learning curve but are definitely worth it!  This is a short overview of the strength of using a macro to run the descriptives command.

Word of warning, make sure you re-define your macro before calling it.  This is an easy step to forget and you can waste a lot of time.

Intro to SPSS Macro Call

Video tutorials demonstrating the usage of the SPSS Macro

Additional SPSS macro links

A great resource to use and learn macros is Raynald Levesque’s site.  This page is his intro to macros page and this one walks through writing one.  He also has a great library of them located here.

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 …

Quick Intro to SPSS progams | Glenn Thompson’s Homepage

Feb 13, 2010 Free Power Calculation Resources · automation program for  · Quick Intro to SPSS Working with SPSS …

Replacing missing data

https://www.youtube.com/watch?v=5CBm_F3zBOo 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 …

Use an SPSS Macro to Open and Save Hundreds /Thousands of similar Files

SPSS macro to open and save

Using an SPSS Macro to Open and Save files can be quite a time saver!  In my example code & video I demonstrate how to adapt basic SPSS syntax into a macro that automates the process.   I also mention this macro which takes the reverse approach (automatically breaks the file into random groups).

The below code it just an example using SPSS macro to open and save text files which will have to be adapted to your needs.  Be sure to pay close attention to string variables and the widths you set them at.  Generally speaking, set them at double what SPSS assigns them.  In reality, there doesn’t seem to be any file-size change when you make them very wide so you also might just default to setting the width to 10X the width (then shrink the column widths with the Var Width command.

In the video I also demonstrate how I used Excel to help write my syntax for looping over all the files as well as merging the files together.

SPSS macro to open and save Text files

DEFINE !OpenSav (In_Path !TOKENS (1) /Out_Path !TOKENS (1) / File_Name !TOKENS (1) )
 script "B:\SPSS\Scripts\Empty.sbs".
GET DATA  /TYPE=TXT  /FILE=!In_Path + !File_Name + ".txt"
 Company A120
 City A30
 State F3.0
 Sales_Rev F11.0
 Num_Emp F6.0.
Var width All (5) company city (10) .
SAVE OUTFILE=!Out_Path + !File_Name + ".sav"  /COMPRESSED.
!OpenSav In_Path="H:\temp\Files\"  Out_Path="H:\temp\Out\"    File_Name="Rand_1".

Video demonstrating using an SPSS macro to open and save files

SPSS macro to remove characters from strings

SPSS macro

SPSS macro to remove characters from strings

While SPSS has many strengths, string manipulation is NOT one of them! Don’t get me wrong, you can manipulate strings however the syntax for doing so is very complex.

If you are still using an older version of SPSS, this macro shows how you can easily remove character(s) from a string both anywhere in the string or at a certain location.  Newer versions have a Replace command which can be used to remove unwanted characters.

Video demonstrating SPSS macro to remove characters from strings