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

Video demonstrating using an SPSS macro to open and save files

Use an SPSS Macro to Open Hundreds of similar 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

 

Removing charchters from strings in SPSS