SPSS Data List

The DATA LIST command reads data.


Usage

Fixed

To read fixed-width input, try:

data list fixed / CaseNum 1-2 Score 4-6.
begin data
 1  10
 2  40
 3  15
 4  10
 5  15
 6
 7  25
 8  10
end data.

This command results in the following dataset:

!CaseNum

Score

1

10

2

40

3

15

4

10

5

15

6

7

25

8

10

This is the default behavior of the DATA LIST command, and the FIXED option can be left off.

See here for information about input formats.

Free

To read free-field input for which record delimiters do not matter, try:

data list free / CaseNum (F2) Score (F3).
begin data
1, 10, 2, 40, 3, 15, 4, 10, 5, 15, 6,, 7, 25, 8, 10
end data.

The default delimiter is a comma (,). To use an alternative delimiter, specify the list of characters within parentheses following the FREE option. For example, FREE (':', ';'). The keyword TAB can also be specified within the parenthesized list for tab-delimited data.

Values can optionally be quoted in either single (') or double quotes ("). Any amount of whitespace is equivalent to a single space for separating values, but consecutive delimiters cause a variable to be skipped.

This command results in the same dataset as above.

See here for information about print and write formats. Note however that numeric variables are read irrespective of the width and decimal places. It can still be meaningful to provide a date or time format to ensure accurate value parsing, and string formats must be accurately declared.

List

To read free-field input with meaningful record delimiters try:

data list list / CaseNum (F2) Score (F3).
begin data
1, 10
2, 40
3, 15
4, 10
5, 15
6
7, 25
8, 10
end data.

This command results in the same dataset as above.

Table and NoTable

By default, SPSS will print a table describing the data read in. Add the TABLE option to explicitly allow this behavior, or add the NOTABLE option to disable it.

File and Encoding

The above examples show reading data from input, between the BEGIN DATA and END DATA commands. Alternatively, a file can be read in. Set the FILE and ENCODING options accordingly.

data list file="path/to/data.txt" encoding="1252" free / CaseNum (F2) Score (F3).

Skip

The SKIP option can be specified to skip, for example, a header row.

data list file="path/to/data.txt" skip=1 free / CaseNum (F2) Score (F3).

End

Another alternative for reading in data is using one or more INPUT PROGRAM commands. The logic for using these often depends upon flag variables describing the current state of input. The END option specifies a variable that should be set to 1 upon completion.

input program.
  numeric #a #b.
  do if #a.
    data list notable end=#b file='b.txt' fixed / X 1-10.
    do if #b.
      end file.
    else.
      end case.
    end if.
  else.
    data list notable end=#a file='a.txt' fixed / X 1-10.
    do if not #a.
      end case.
    end if.
  end if.
end input program.

The END option is only valid when reading fixed-width input.


See also

PSPP manual for DATA LIST


CategoryRicottone

SPSS/DataList (last edited 2023-06-14 19:12:29 by DominicRicottone)