Moving data from one column to many; Parsing a variable using an SPSS macro

one column to many

Older online vendor tools and databases would frequently put multi-select questions into one column having a pipe,tab,semicolon or comma delimiter (what was real fun is when they would use a comma for a delimiter in a CSV file).

This can be very problematic in nearly any tool. In this video I demonstrate how easy it can be to move data from one column to many with an SPSS macro.

Move one column to many

Here is the SPSS macro demonstrated in the video:

DEFINE !Parse (Var !TOKENS (1)  / Stem !TOKENS (1) /Del !TOKENS (1))
STRING #(A1000).
VECTOR !Stem(25A500).
COMPUTE #cnt=1.
LOOP IF INDEX(#,!Del)>0.
COMPUTE !Stem(#cnt)=SUBSTR(#,1,INDEX(#,!Del)-1).
COMPUTE #cnt=#cnt + 1.
Var width !Concat(!Stem,1) to !Concat(!Stem,25) (10).
/* !Parse Var=NAIC_All Stem=NAIC  Del=";".


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.