splitit.pl -- Convert Multi-column Variable Statements into Single Column


This Perl script reads a file containing multi-column SAS Input or SPSS Data List statements and converts them into a single-column format with one statement per line. It is good for checking your input declarations when preparing your code or for modifying the statements with scripts since you can loop over a single column easily.

Intended for larger lists of variables, this program will process many statements very quickly. I used to use it for SAS and SPSS input statements for large social sciences studies with hundreds or thousands of variables. It saved a lot of time.

See also wrapit which creates a multi-column format from the single column output of splitit.

This utility is part of my collection of text-processing tools.

Usage

The command line is: perl splitit.pl filename >filename.out

Here is an example. Consider this input data:

Sample input (cards):

   V1 1-4         V2 5-8         V3 9-9         V4 10-13 (A)   V5 14-14
   V6 15-16       V7 17-17       V8 18-19       V9 20-21      V10 22-23
  V11 24-25      V12 26-26      V13 27-28      V14 29-33 (A)  V15 34-35
  V16 36-37      V17 38-39      V18 40-41      V19 42-46 (A)  V20 47-47

The command 
perl splitit.pl cards > cards.split produces this:

Sample output (cards.split)

   V1 1-4         
   V2 5-8         
   V3 9-9         
   V4 10-13 (A)   
   V5 14-14 
   V6 15-16       
   V7 17-17       
   V8 18-19       
   V9 20-21      
   V10 22-23 
   V11 24-25      
   V12 26-26      
   V13 27-28      
   V14 29-33 (A)  
   V15 34-35 
   V16 36-37      
   V17 38-39      
   V18 40-41      
   V19 42-46 (A)  
   V20 47-47 


Back to Kent's Perl Page Last modified: Sat Sep 6 17:20:11 EDT 2025 free counters