ARCHIVED: How can I read raw data from a Pipe-Delimited text file into SAS?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

Assume a file named test.txt with a pipe-delimited text format:

  ID|Age|Sex|Income|Race|Hight|Weight 1|30|F|3400|Black|160|53
  2|34|M|4000|White|178|78 3|28|M|3500|Hispanic|183|75
  4|45|F||Black|165|72

To read this example raw data in SAS, the basic SAS code would be:

  Data test;
  Infile  "C:\Users\test.txt"
  DLM='|' DSD LRECL=400 FIRSTOBS=2; 
  Input ID Age Sex $ Income Race $ Hight Weight;
  run;
  • The DLM option allows you to tell SAS what character is used as the delimiter in the text file.

    This assumes the data set in the text file has a comma-delimiter (,), pipe-delimiter (|), put , or a pipe-delimiter between the quotation marks, respectively. If this option is not specified, SAS assumes a space delimiter.

  • The DSD option is usually used when the text file has consecutive delimiters because of missing values, such as in the example's last line.

    It tells SAS to treat each delimiter separately; otherwise, SAS treats two delimiters as one and reads data without missing values.

    Additionally, the DSD option can also be used to remove any existing quotes around values in the text file.

  • Use the LRCEL option when the length of the records in a file is greater than the default length of 256 bytes; otherwise, they will be truncated.
  • The FIRSTOBS option designates which line should be read as first values.

For alternatives to reading raw text files with special delimiters, use StatTransfer in Windows or Quarry. See:

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document bcjf in the Knowledge Base.
Last modified on 2023-05-09 14:39:30.