wrapit5.pl -- Wrap SAS or SPSS Variable Input Statements to Multiple Columns


This 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

Back to Kent's Perl Page Last modified: Tue Mar 17 09:50:22 EDT 2026