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

Converting Yes-No Strings to Numerics with an SPSS Macro

SPSS macro

Often I have strings in my SPSS data set which have values like: Y,Yes,yes,No,n, etc. and I want them to be a numeric value so I can take their mean. This SPSS macro makes converting them a breeze!  You might need to adapt it to your data set but the principle can be applied for many uses.

The below video demonstrates it usage.  Definitely saves a lot of time if o

SPSS macro

These SPSS macros should regularly categorize the string variables correctly.

 
*/////////////////////.
DEFINE !con2Num (vnames=!CMDEND)
!DO !vname !IN (!vnames)
If INDEX(Upcase(!Vname),Upcase("Y"))>0 Temp1234= 1 .
If INDEX(Upcase(!Vname),Upcase("N"))>0 Temp1234= 0 .
FORMAT temp1234(F3.0).
Val Labels Temp1234 0"No" 1"Yes".
Var level Temp1234 (Scale).
MATCH FILES FILE=* /DROP=!vname .
RENAME VARIABLE (temp1234=!vname).
!DOEND
exe.
!ENDDEFINE.
*/////////////////////.
!con2Num vnames=var1 var2 var3 .

*/////////////////////.
DEFINE !con2NumNA (vnames=!CMDEND)
!DO !vname !IN (!vnames)
If INDEX(Upcase(!Vname),Upcase("N"))>0 Temp1234= 0 .
If INDEX(Upcase(!Vname),Upcase("Y"))>0 Temp1234= 1 .
If INDEX(Upcase(!Vname),Upcase("N/A"))>0 OR INDEX(Upcase(!Vname),Upcase("NA"))>0 Temp1234= 2 .
FORMAT temp1234(F4.0).
Var level Temp1234 (Nominal).
Val Labels Temp1234 0"No" 1"Yes" 2"NA".
MATCH FILES FILE=* /DROP=!vname .
RENAME VARIABLE (temp1234=!vname).
!DOEND
exe.
!ENDDEFINE.
*/////////////////////.

!con2NumNA vnames=var1 var2 var3 .

Here are some convenient references to learn more.

Learning SPSS Macros | Raynald’s SPSS Tools

This page is a simple introduction. There are several fully (line- by-line) commented examples of macro

Windows autocorrect- Use AutoHotKey to replace text in any Windows program

windows autocorrect

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.

Text file explorer-Determine file headers & delimiters without opening file

Text file explorer

Text File ExplorerText file explorer

I often work with large text files in which the file extension (.txt, .dat, .csv, .tab) doesn’t always indicate what type of delimiter is used in the file.  When the file is small, I’ll typically just “pop” it open in SciTE / Notepad.  Large files (anything over 20 megs) often take a fair amount of time to read and very large files ( a gig or more) will often run into out of memory issues.

On top of wanting to know the delimiter, I also frequently want to know what fields / Headers are in the file.   This normally means I have to open it in a text editor or Excel and review.  I wrote the below Text File Explorer in AutoHotkey script to simplify the above.  I can highlight a file from Windows Explorer and quickly detect the type of delimiter plus display headers if I care to.

Text file explorer AutoHotkey code:


Here’s a video demonstrating the usage of the Text file Explorer