For the purposes of this tutorial we will be using the following XTAB program fragment:

*files
 input xt_data.txt

*variables
 lastname/Last Name/1-10
 firstname/First Name/11-20
 age/Age/21-22
 race/Race/23
 sex/Sex/24
 county/County/25-26
 company/Company/27-36
 phone//37-46
 ac/Area Code/37-39
 ssn/Social Security Number/47-55
 salary/Salary/56-60
 title/Job Title/61
 class/Classification/62

The file xt_data.txt was generated utilizing the perl script xt_dgen.pl. It contains 1000 lines. It is to serve as our demonstration file.


First we will show a couple of file processing capabilities of XTAB:

Print the first 25 lines of the file:

*files
 input xt_data.txt
 limit 25

*instructions
 print data

(Data is the default name of the input record.)

Write all Males to a file.

*files
 input xt_data.txt
 output file01 /v001/maledemo.txt

*variables
 sex/Sex/24

*instructions
 select sex eq M
 write file01 data

Now we will show some cross tabulations.

A simple sex vrs race table:

*files
 input xt_data.txt

*variables
 sex/Sex/24
 race/Race/23

*tables
 table
 stub sex codes M,F
 spread race W,B,#

(The # means everything else).

Now lets add some labels:

*files
 input xt_data.txt

*variables
 sex/Sex/24
 race/Race/23

*tables
 table Sex by Race Breakdown
 labels Men,Women
 stub sex codes M,F
 labels While, Black, Others
 spread race W,B,#

Now lets add the same table, but just with supervisors.

*files
 input xt_data.txt

*variables
 sex/Sex/24
 race/Race/23
 class/Classification/62

*tables
 table Sex by Race Breakdown
 labels Men,Women
 stub sex codes M,F
 labels While, Black, Others
 spread race W,B,#

 table Sex by Race Breakdown,,Supervisors
 select class eq S
 labels Men,Women
 stub sex codes M,F
 labels While, Black, Others
 spread race W,B,#

(We can do multiple tables, of differing stubs and spreads, with differing selection criteria in a given run).


Now lets do a table of companys and salary ranges.

*files
 input xt_data.txt

*variables
 company/Company/27-36
 salary/Salary/56-60

*tables
 table Companys and the Salary ranges they pay:
 stub company freq 20
 spread salary values 0-30000,30001-65000,65001-99999

In the above we may not know all the companys on the file so we say show me the first 20 unique ones. Since salary is numeric we use the key word values instead of codes.