Command reference

import delimited — read a CSV or delimited text file

Load a text file into the current dataset. Each row becomes an observation and each field becomes a variable. The importer detects common separators and chooses numeric or text types from the file contents.

Syntax

import delimited "filename.csv" [, options]

Replace filename.csv with the path to a file in your project. Put paths in double quotes, especially when they contain spaces. Options follow a comma; for example, import delimited "scores.csv", clear varnames(1).

Options

clear
Replace the dataset currently in memory. Without this option, importing while a dataset is open produces an error so that the existing data are not lost.
delimiter(";")
Set the character separating fields; this example selects a semicolon. If omitted, the importer tries to detect the separator, including comma, tab, and semicolon. Check the import message if columns do not look right.
varnames(1)
Explicitly treat the first row of the detected table as variable names. Without this option, the importer detects whether the file has a header. Only the value 1 is supported here.

Example

This example loads 24 synthetic student records, lists their variable definitions, and summarizes math, reading, and writing scores. It demonstrates the checks to make immediately after an import.

clear
import delimited "data/student_scores.csv"
describe
summarize math read write
Open example in browser

Sample data included. Opens in a new tab; click Run.

What to look for

The imported dataset has six variables and 24 observations. Math and reading each have 24 observed values; writing has 23 because one value is missing. A lower observation count in a summary therefore does not necessarily mean that a row was lost during import.