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

Configure your SPSS variable format properly using syntax

SPSS variable

SPSS Variable Formats

If you’re you want to have pretty-looking tables / output, having your data in the proper format really helps.  (not to mention that SPSS is “smart” and will prevent showing them in some GUI procedures if your variable is the “wrong” type.)

While the GUI window to the data editor makes it easy to adjust the variable level, format, type,etc.  I had a hard time finding the correct syntax to set them programatically.

This video helps with some of the more-common settings.  Below is the syntax for tweaking SPSS variable level and format.

 
************CHANGE DATA LEVEL******************* .
VARIABLE LEVEL var1 var2 (Nominal).
VARIABLE LEVEL var1 var2 (Ordinal).
VARIABLE LEVEL var1 var2 (Scale).

************FORMAT VARIABLE******************* .
****Numeric with TWO decimal places**************************.
FORMAT var1 var2 (F5.2).

****Numeric with ZERO decimal places**************************.
FORMAT var1 var2 (F5.0).

****Comma with ZERO decimal places**************************.
FORMAT var1 var2 (COMMA4.0).

****Dollar with TWO decimal places**************************.
FORMAT var1 var2 (DOLLAR6.2).

****Percents with ONE decimal place**************************.
FORMAT var1 var2 (PCT4.1).

 

https://www.youtube.com/watch?v=dj9Tu-rkfmY

Check out my post on setting SPSS variables for missing data!

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

https://www.youtube.com/watch?v=N-_5G5VBLC8

 

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.

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

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.