SPSS Non-interactive Execution

SPSS allows you to execute your job either in interactive or non-interactive mode. For noninteractive execution, you must first create an SPSS command file containing SPSS commands. Let us take an annotative example, clas1.sps, to demonstrate it. This file, clas.dat, uses an external data file clas.sps.

In this clas1.sps, we will

  1. List the data for grade, years of computing experience, and total for math attitude scale;
  2. Do a one-way analysis of variance with grade as the independent variable and math attitude as the dependent variable; and
  3. Do a simple regression with years computing experience as the independent variable and the math attitude as the dependent variable.

Now, Let's have a quick look at the external data file, clas.dat. You may find that the data means nothing to you unless it has proper explanation. (The original CLAS.DAT has 50 cases. For the sake of simplicity, here only 10 cases are listed. In your own SPSS external data file, it is recommended that you have such a fixed format.) Notice that line 8 has a blank meaning "missing value", which will be explained later.

01F1111115155222521412344423028
02F1111212155125521522244422825
03F2111124254214445155511144531
04F2121442322232245155511244243
05F1121541221241244145412154844
06F1122124254224544145412155040
07F2122224144225555155511244033
08F2222   244224421412234422932
09F2222115155115421412244412524
10F2222114155124544154511159925

Notice that the following SPSS commands are typed in upper-case, whereas the comments are typed in normal mode and start with an asterisk (*). In the real world, SPSS accepts both upper-case and lower-case, and ignores the lines beginning with an asterisk.

TITLE 'COMPUTER ANXIETY IN MIDDLE SCHOOL CHILDREN'
* The title should be enclosed in apostrophes as the above line.
* Title can be up to 60 characters long.

DATA LIST FILE=CLAS.DAT NOTABLE
* The DATA LIST command tells SPSS where the data can be found.
* The FILE= indicates the external file containing the raw data.
* The subcommand NOTABLE tells SPSS not to create a table that
* summarizes your variable definitions right after DATA LIST.

 /ID 1-2 SEX 3 (A) AGE 4 GRADE 5 EXP 6 COUNTY 7  C1 TO C10 8-17
  M1 TO M10 18-27 MATHSCOR 28-29 COMPSCOR 30-31
* The list of variables and their locations should be preceded
* by a slash (/).  A string variable "(A)" is specified after
* the variable name and column location.

MISSING VALUES MATHSCOR COMPSCOR (99)
* MISSING VALUES instructs SPSS that 99 is the user-defined missing
* value to deal with dependent variables MATHSCOR and COMPSCOR.

RECODE C3 C5 C6 C10 M3 M7 M8 M9 (1=5) (2=4) (3=3) (4=2) (5=1)
* The RECODE command tells the SPSS to change the values for a variable
* as the data are being read, e.g. change value 1 to value 5.

COMPUTE COMPOPI = SUM (C1 TO C10) 
COMPUTE MATHATTI = SUM (M1 TO M10)
* These two lines compute the sum of values across the arguement lists
* for computer and mathematical attitude and save the result into
* COMPOPI and MATHATTI.

VARIABLE LABELS ID 'STUDENT IDENTIFICATION' SEX 'STUDENT GENDER'
    AGE 'STUDENT AGE' GRADE 'STUDENT GRADE' EXP 'YRS OF COMP EXPERIENCE'
    COUNTY 'COUNTY REPRESENTING' COMPSCOR 'SCORE IN COMPUTER SCIENCE' 
    COMPOPI 'TOTAL FOR COMP SURVEY' MATHATTI 'TOTAL FOR MATH ATTI SCALE'
* VARIABLE LABELS command supplies information that is used for
* labeling SPSS display output so as to make it more descriptive.

VALUE LABELS SEX 'M' 'MALE' 'F' 'FEMALE'/
    AGE 1 '13' 2 '14' 3 '15' 4 '16'/GRADE 1 '7' 2 '8' 3 '9'/
    EXP 1 'LESS THAN 1 YR' 2 '1 YEAR' 3 '2 OR MORE'/
    COUNTY 1 'MONROE' 2 'BROWN' 3 'MORGAN' 4 'GREENE' 5 'MARION'/
    C1 TO C10 1 'STROGNLY DISAGREE' 2 'DISAGREE'
    3 'UNDECIDED' 4 'AGREE' 5 'STRONGLY AGREE'/
    M1 TO M10 1 'STROGNLY DISAGREE' 2 'DISAGREE'
    3 'UNDECIDED' 4 'AGREE' 5 'STRONGLY AGREE'/
* VALUE LABELS command provides descriptive labels for values.  Notice
* that variable and value labels are enclosed within apostrophe (').
* Use slash (/) to separate each value label.

PRINT FORMATS GRADE EXP MATHATTI (F2.0)
* PRINT FORMATS specifies a total width of 2 characters, with no
* decimal places, for variables GRADE, EXP and MATHATTI.
* This will print the student grade, years of computer experience,
* and total for mathematical attitude scale.

ONEWAY MATHATTI BY GRADE (1,3)
* The procedure ONEWAY produces a one-way analysis of variance.
* MATHATTI is the dependent variable and GRADE is the independent variable.

REGRESSION WIDTH=80
  /DEPENDENT=MATHATTI
  /METHOD=ENTER EXP
* The REGRESSION procedure is to calculate the least-squares line.
* The WIDTH subcommand is to control the width of the display
* produced by the REGRESSION procedure.  The /DEPENDENT subcommand
* indicates the dependent variable for regression analysis, whereas
* the /METHOD=ENTER subcommand indicates the independent variable

FINISH.
* The FINISH command terminates an SPSS session.  Any commands
* following FINISH are ignored.

From the previous annotative program, you should have an initial impression of frequently used SPSS commands. If you are copying the file from the directory specified on statmath account, you have to enter a few more command lines from the example given here, as that command file is not exactly identical to this example. You may use one your favorite unix editors to do that.

Once you create your own file, execute it with the syntax:

    spss -m < clas1.sps > clas1.out &

Notice that clas1.out is the output file and clas1.sps is the input file. The & will enable you to run the job as a background process and free your terminal for other computing activities while the job runs in the background. If the & is not included, your terminal will not be free for other computing activities until the job is completed.

Once the job is completed the output file will be stored in the default directory.