IMPORT Procedure

PROC IMPORT Statement

Imports an external data file to a SAS data set.

Syntax

Required Arguments

DATAFILE="filename" | "fileref"

specifies the complete path and filename or fileref for the input PC file, spreadsheet, or delimited external file. A fileref is a SAS name that is associated with the physical location of the output file. To assign a fileref, use the FILENAME statement. For more information about the FILENAME statement, see SAS Statements: Reference. For more information about PC file formats, see SAS/ACCESS Interface to PC Files: Reference

If you specify a fileref or if the complete path and filename does not include special characters such as the backslash in a path, lowercase characters, or spaces, then you can omit the quotation marks.
Restrictions The IMPORT procedure does not support device types or access methods for the FILENAME statement except for DISK. For example, the IMPORT procedure does not support the TEMP device type, which creates a temporary external file.
The IMPORT procedure can import data only if SAS supports the data type. SAS supports numeric and character types of data but not (for example) binary objects. If the data that you want to import is a type that SAS does not support, the IMPORT procedure might not be able to import it correctly. In many cases, the procedure attempts to convert the data to the best of its ability. However, conversion is not possible for some types.
Interactions When you use a fileref to specify a delimited file to import, the logical record length (LRECL) defaults to 256, unless you specify the LRECL in the FILENAME statement. The maximum LRECL that the IMPORT procedure supports is 32767.
For delimited files, the first 20 rows are scanned to determine the variable attributes. You can increase the number of rows scanned using the GUESSINGROWS data source statement. All values are read in as character strings. If a Date and Time format, or numeric informat can be applied to the data value, the type is declared as numeric. Otherwise, the type remains character.
Importing a Delimited File

Importing a Specific Delimited File Using a Fileref

Importing a Tab-Delimited File

Importing a Comma-Delimited File with a CSV Extension

OUT=<libref.>SAS data set

identifies the output SAS data set with either a one or two-level SAS name (library and member name). If the specified SAS data set does not exist, the IMPORT procedure creates it. If you specify a one-level name, by default the IMPORT procedure uses either the USER library (if assigned) or the WORK library (if USER is not assigned).

In the first maintenance release of SAS 9.4, a SAS data set name can contain a single quotation mark when the VALIDMEMNAME=EXTEND system option is also specified. Using VALIDMEMNAME= expands the rules for the names of certain SAS members, such as a SAS data set name. For more information, see “Rules for SAS Data Set Names, View Names, and Item Store Names” in SAS Language Reference: Concepts.
Importing a Delimited File

Importing a Specific Delimited File Using a Fileref

Importing a Tab-Delimited File

Importing a Comma-Delimited File with a CSV Extension

TABLE="tablename"

specifies the name of the input DBMS table. If the name does not include special characters (such as question marks), lowercase characters, or spaces, you can omit the quotation marks. Note that the DBMS table name might be case sensitive.

Requirements You must have a license for SAS/ACCESS Interface to PC Files to import to a DBMS table.
When you import a DBMS table, you must specify the DBMS= option.

Optional Arguments

DBMS=identifier

specifies the type of data to import. You can import delimited files or JMP files (DBMS=JMP). The JMP file format must be Version 7 or later. JMP variable names can be up to 255 characters long. SAS supports importing JMP files that have more than 32,767 variables.

To import a tab-delimited file, specify TAB as the identifier. To import any other delimited file that does not end in .CSV, specify DLM as the identifier. For a comma-separated file with a .CSV extension, DBMS= is optional. The IMPORT procedure recognizes .CSV as an extension for a comma-separated file.
See DBMS Identifiers Supported in Base SAS for more information about identifiers for this option.
SAS/ACCESS Interface to PC Files: Reference for a list of additional DBMS values when using SAS/ACCESS Interface to PC Files.
Importing a Delimited File

Importing a Specific Delimited File Using a Fileref

Importing a Tab-Delimited File

Importing a Comma-Delimited File with a CSV Extension

REPLACE

overwrites an existing SAS data set. If you do not specify REPLACE, the IMPORT procedure does not overwrite an existing data set.

Importing a Delimited File

Importing a Specific Delimited File Using a Fileref

Importing a Tab-Delimited File

Importing a Comma-Delimited File with a CSV Extension

SAS data set options

specifies SAS data set options. For example, to assign a password to the resulting SAS data set, you can use the ALTER=, PW=, READ=, or WRITE= data set option. To import only data that meets a specified condition, you can use the WHERE= data set option.

Restriction You cannot specify data set options when importing delimited, comma-separated, or tab-delimited external files.
See SAS Data Set Options: Reference.