wrapit -- Wrap SAS or SPSS Variable Input Statements to Multiple Columns

Note: this page contains both wrapit and splitit program information.


This first Perl script reads a file containing a single column of SAS Input or SPSS Data List statements and changes them into a wrapped format with multiple fields per line--defaulting to five columns wide. Handy for making long, single-column SAS or SPSS input declarations more compact and readable in your code.

You can edit SAS or SPSS statements by hand in an editor, by why? You can format them quickly with this script. For a small number of statements, it's not a problem. But I used do hundreds to thousands of variables in an input statement and formatting them with an editor would have been very tedious. Thus, I wrote this small program to do the job and it has been a time-saver.

Usage

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

This utility is part of my collection of my Perl text-processing tools.
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 wrapit5.pl cards > cards.wrap produces this:

 Sample output (cards.wrap):

   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

 


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


splitit is the inverse operation of wrapit. It takes a wrapped multi-column layout and splits it into a single column. wrapit does the opposite.

This second 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. If you'd rather use a text editor to do this manually, it gets boring quickly.

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: Wed Oct 7 20:44:26 EDT 2026